String数组转为byte数组
时间: 2024-05-27 07:13:06 浏览: 132
将一个 String 数组转为 byte 数组可以使用 String 类的 getBytes() 方法。具体可以参考以下代码:
String[] strArray = {"hello", "world"};
byte[][] byteArrays = new byte[strArray.length][];
for(int i = 0; i < strArray.length; i++){
byteArrays[i] = strArray[i].getBytes();
}
相关问题
byte数组转为string
可以使用以下代码进行byte数组转为string:
```java
byte[] bytes = new byte[]{65, 66, 67};
String str = new String(bytes);
System.out.println(str);
```
输出结果为:ABC。
当然,具体实现也要看具体的业务需求和编码格式。
byte数组 转为string
可以使用System.Text.Encoding类的GetString方法将byte数组转为string。例如:
byte[] bytes = { 72, 101, 108, 108, 111 }; // "Hello"的byte数组表示
string str = System.Text.Encoding.Default.GetString(bytes); // 转为string
Console.WriteLine(str); // 输出 "Hello"
阅读全文
相关推荐














