richersoon richersoon - 1 year ago 49
Java Question

Simpliest way to convert array of Integer to array of String in Java 8

I would like to convert an

Integer[]
but
toArray()
is giving me
Object[]
. How can I convert it to
String[]
?

Stream.of(ids).map(String::valueOf).toArray();

Answer Source
String[] array = Stream.of(ids).map(String::valueOf).toArray(String[]::new);