How do I get an IntStream from a List<Integer>?
问题 I can think of two ways: public static IntStream foo(List<Integer> list) { return list.stream().mapToInt(Integer::valueOf); } public static IntStream bar(List<Integer> list) { return list.stream().mapToInt(x -> x); } What is the idiomatic way? Maybe there is already a library function that does exactly what I want? 回答1: I guess (or at least it is an alternative) this way is more performant: public static IntStream baz(List<Integer> list) { return list.stream().mapToInt(Integer::intValue); }