Java 8 way to convert int[][] to Integer[][]

Aashish Pawar :

How to convert java int[][] to Integer[][] ? .It seems easy to convert single dimensional primitive array to Object type single dimensional array using java stream.

For example

Integer[] result = IntStream.of( intarray ).boxed().toArray( Integer[]::new );

Is there any way for two dimensional array like above ?

Michael :

You can do the same thing within a map operation

int[][] twoDimenArray = {};
Integer[][] result = Stream.of(twoDimenArray)
    .map(array -> IntStream.of(array).boxed().toArray(Integer[]::new))
    .toArray(Integer[][]::new);

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=20599&siteId=1