Java 字节数组到字符数组的转换

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28854837/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 06:57:05  来源:igfitidea点击:

Byte array to Char Array conversion

java

提问by Arjun

My byte array is look like

我的字节数组看起来像

 byte[] x = { (byte) 0xff , (byte) 0x80  };

how can i convert it to char array {char[] y } where:-

我如何将其转换为字符数组 {char[] y } 其中:-

y[0]='f';
y[1] ='f' and so on

回答by BeWu

This should help you:

这应该可以帮助您:

byte[] data = { (byte) 0xff , (byte) 0x80  };
String text = new String(data, "UTF-8");
char[] chars = text.toCharArray();