Is there easy way to get Array object from collection in Java? Easy way to transform Collection to Array?
Suppose you have a collection with the name myCol then you can use the following code:
String myArray = myCol.toArray(new String);
Above is using Java 7. But you can also do like this in Java 8:
String result = myCol.stream() .map(x -> new String(x)) .toArray(size -> new String[size]);
Above code is using the stream in Java 8.
We have huge collection of Java util package examples check all at Java Util Examples.