List<Integer> to int[]

To convert List<Integer> to int[] in java we can use les Streams, With Java 8, int[] can be converted to Integer[] easily :

int[] data = {1,2,3,4,5,6,7,8,9,10};

// To boxed array
Integer[] what = data ).boxed().toArray( Integer[]::new );
Integer[] ever = IntStream.of( data ).boxed().toArray( Integer[]::new );

// To boxed list
List<Integer> you  = data ).boxed().collect( Collectors.toList() );
List<Integer> like = IntStream.of( data ).boxed().collect( Collectors.toList() );

Integer[] is generally not a good map key, as others have said. However, we now have a reasonably clean and native code in terms of conversion.

Also read , How to convert String to int ?



  1. Pingback: (SOLVED) how to Convert File to Path in Java ? » JavaTuto

Laisser un commentaire