Search code examples
javaarraysarraylistprimitive-types

Convert ArrayList<Byte> into a byte[]


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[].


Solution

  • 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->