import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class Test1 {
public static void main(String[] args) {
int[] nums = {1, 2, 3, 4};
//先装箱然后collect算子将将结果转换为List
List<Integer> temp = IntStream.of(nums).boxed().collect(Collectors.toList());
for (Integer integer : temp) {
System.out.println(integer);
}
}
}
Java8<使用流API优雅地将int[]转换为ArrayList>
最新推荐文章于 2024-08-09 09:15:00 发布