11智能在线
新记
java里面byte数组和String字符串怎么转换
如题所述
举报该文章
相关建议 2016-11-25
1、string 转 byte[]
String str = "Hello";
byte[] srtbyte = str.getBytes();
2、byte[] 转 string
byte[] srtbyte;
String res = new String(srtbyte);
System.out.println(res);
3、设定编码方式相互转换
String str = "hello";
byte[] srtbyte = null;
try {
srtbyte = str.getBytes("UTF-8");
String res = new String(srtbyte,"UTF-8");
System.out.println(res);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
温馨提示:内容为网友见解,仅供参考
当前网址:
https://11.t2y.org/zz/vp7qm2qm7q24mf7v7s.html
其他看法
第1个回答 2016-11-25
将数组内容转换成字符串:用的join方法
例如:数组arr={1,2,3,4};
arr1 = arr.join(",");
那么得到的arr1是一个字符串“1,2,3,4”
集合变数组用split(",")方法.表示将字符串按照逗号切割
相似回答
大家正在搜
相关问题
java里面byte数组和String字符串怎么转换
java里面byte数组和String字符串怎么转换
java里面byte数组和String字符串怎么转换
java里面byte数组和String字符串怎么转换
java怎样把string字符串转化为string字符串数组
如何将json格式的string字符串转换为string数组
如何将json格式的string字符串转换为string数组
java怎么将字符串型数组转换成字符串