Java getBytes() 方法

Java getBytes() 方法

可用如下方法查看字符串用 getBytes() 方法处理后返回的 byte[] 数组中的内容:

class Main {

public static void main(String[] args) {

String str = "make a fortune";

byte[] byt = str.getBytes();

for (byte b : byt) {

System.out.println(b);

}

}

}

以上程序运行结果为:

109

97

107

101

32

97

32

102

111

114

116

117

110

101

可见 byte[] 数组中存放的是字符串响应位置对应的字母的哈希值,如字符串中的字母 a 对应 byte[] 数组中的 97 。

另外:返回的 byte[] 数组的长度,与原字符串的长度相等。

Make a fortune Make a fortune

540***949@qq.com

8年前 (2018-04-28)

你可能也喜欢

没有花户必下款的口子,这10个门槛低、容易审批、通过率高
iPhone Screenshots
Microsoft 365安卓

iPhone Screenshots

08-20 6162
吸烟成瘾的明星有哪些?这些明星都爱抽什么烟?