As below:
IntStream iStream = IntStream.range(1,4);
iStream.forEach(System.out::print);
List list1 = iStream.collect(Collectors.toList());//error!
Java 1.8 compiler gives type deduction error. Similar code could work for String type:
List<String> ls = new ArrayList<>();
ls.add("abc");
ls.add("xyz");
List list2 = ls.stream().collect(Collectors.toList());
Why? Does IntStream/LongStream/DoubleStream are not working the same way like other types? How to fix my compilation error?
boxed ()
before collecting. – Beneficent