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);
posted @ 2023-11-16 14:50  vx_guanchaoguo0  阅读(102)  评论(0编辑  收藏  举报