Java 8 has given us an easy way to do this via streams...
Using the collections stream()
function and then mapping to ints, you'll get an IntStream. With the IntStream
we can call toArray() which gives us int []
int [] ints = list.stream().mapToInt(Integer::intValue).toArray();
to int []
to IntStream