我有一个byte []的ArrayList,我想知道是否可以使用Java*中的流将其转换为byte [].ArrayList中的所有数组都具有相同的大小.
ArrayList<byte[]> buffer = new ArrayList();
byte[] output = buffer.stream(...)
Run Code Online (Sandbox Code Playgroud)
sak*_*029 10
试试这个.
List<byte[]> list = Arrays.asList("abc".getBytes(), "def".getBytes());
byte[] result = list.stream()
.collect(
() -> new ByteArrayOutputStream(),
(b, e) -> {
try {
b.write(e);
} catch (IOException e1) {
throw new RuntimeException(e1);
}
},
(a, b) -> {}).toByteArray();
System.out.println(new String(result));
// -> abcdef
Run Code Online (Sandbox Code Playgroud)