Possible Duplicate:
How to convert an ArrayList containing Integers to primitive int array?
How to convert an ArrayList<Byte>
into a byte[]
?
ArrayList.toArray()
gives me back a Byte[]
.
byte[] result = new byte[list.size()];
for(int i = 0; i < list.size(); i++) {
result[i] = list.get(i).byteValue();
}
Yeah, Java's collections are annoying when it comes to primitive types.
After calling toArray() you can pass the result into the Apache Commons toPrimitive method:
https://commons.apache.org/proper/commons-lang/javadocs/api-release/org/apache/commons/lang3/ArrayUtils.html#toPrimitive-java.lang.Byte:A->
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With