string 和 byte[]转化

poorjack 2001-10-15 08:40:39
比如:
string str1 = "1234"
string str2 = ""
byte[] b;
现要求把str1转化到b,然后再从b转化为string类型str2,分别是什么函数?
...全文
17049 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
hexiaofeng 2001-10-16
  • 打赏
  • 举报
回复
b=str1.getBytes();
str2=String.valueOf(b); or str2 = new String(b);
jsyx 2001-10-15
  • 打赏
  • 举报
回复
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.
cherami 2001-10-15
  • 打赏
  • 举报
回复
b=str1.getBytes();
str2=String.valueOf(b);

62,616

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧