Converting Array to List
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: In order to convert an Integer array to a list of integer I have tried the following approaches: Initialize a list(Integer type), iterate over the array and insert into the list By using Java 8 Streams: int[] ints = {1, 2, 3}; List<Integer> list = new ArrayList<Integer>(); Collections.addAll(list, Arrays.stream(ints).boxed().toArray(Integer[]::new)); Which is better in terms of performance? 回答1: The second one creates a new array of Integers (first pass), and then adds all the elements of this new array to the list (second pass). It will