字节使用byte描述,字节一般主要用于数据的传输或者进行编码的转换。String类里面提供将字符串转换为字节数的方法。
| No | 方法名称 | 类型 | 描述 |
|---|---|---|---|
| 1 | public String(byte[] bytes) | 构造 | 将全部字节数组转换为字符串 |
| 2 | public String(byte[] bytes,int offset,int length) | 构造 | 将部分数组zhuan为字符串 |
| 3 | public byte[] getBytes() | 普通 | 将字符串转换为字节数组 |
| 4 | public byte[] getBytes(String charsetName) throws UnsupportedEncodingException | 普通 | 进行编码转换 |
本文介绍了String类中关于字符串与字节之间的转换方法,包括如何将字符串转换为字节数组,以及如何从字节数组创建字符串。这些转换方法在实际编程中非常实用。

被折叠的 条评论
为什么被折叠?



