Java Byte[] array 字节复制
原始的写法
String key = "abcdef0123456789";
keyBytes = key.getBytes(UTF_8);
for (byte b : keyBytes) {
char c = (char) b;
System.out.print(c);
}
stream lamda
IntStream.range(0, keyBytes.length).mapToObj(i -> (char) keyBytes[i]).forEach(System.out::print);
java Jdk 自带写法
System.out.println(new String(keyBytes, StandardCharsets.US_ASCII));
字节复制 将 16 个字节复制到 24 个字节的数据
- 前16 位补充前 8 位
byte[] keyBytes = new byte[24];
System.arraycopy(key.getBytes(UTF_8), 0, keyBytes, 0, 16);
System.arraycopy(key.getBytes(UTF_8), 0, keyBytes, 16, 8);
本文来自博客园,作者:vx_guanchaoguo0,转载请注明原文链接:https://www.cnblogs.com/guanchaoguo/p/17836246.html