当前位置: 技术问答>java相关
string 和 byte[]转化
来源: 互联网 发布时间:2015-02-10
本文导语: 比如: string str1 = "1234" string str2 = "" byte[] b; 现要求把str1转化到b,然后再从b转化为string类型str2,分别是什么函数? | java.lang Class String byte[] getBytes() Convert...
比如:
string str1 = "1234"
string str2 = ""
byte[] b;
现要求把str1转化到b,然后再从b转化为string类型str2,分别是什么函数?
string str1 = "1234"
string str2 = ""
byte[] b;
现要求把str1转化到b,然后再从b转化为string类型str2,分别是什么函数?
|
java.lang Class String
byte[] getBytes()
Convert this String into bytes according to the platform's default character encoding, storing the result into a new byte array.
static String copyValueOf(char[] data)
Returns a String that is equivalent to the specified character array.
byte[] getBytes()
Convert this String into bytes according to the platform's default character encoding, storing the result into a new byte array.
static String copyValueOf(char[] data)
Returns a String that is equivalent to the specified character array.
|
b=str1.getBytes();
str2=String.valueOf(b);
str2=String.valueOf(b);
|
b=str1.getBytes();
str2=String.valueOf(b); or str2 = new String(b);
str2=String.valueOf(b); or str2 = new String(b);