简体   繁体   中英

java8 stream toArray question - Why i don't need specify array size here for int[][]::new?

Using below code, I could copy 2 dimensional array, but why i don't need specify array size here for int[][]::new?

int[][]source= {{0, 1, 0}, {0, 0, 1}, {1, 1, 1}, {0, 0, 0},{0, 0, 0}};

int[][] destination=Arrays.stream(source)
                    .map(a ->  Arrays.copyOf(a, a.length))
                    .toArray(int[][]::new);

Because what you provide is not an array, but a reference to the method to construct the array. The toArray implementation will provided the size to call the constructor.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM