私の質問は短いのですが、なぜコンパイルできないのですか?
final ArrayList <Integer> list = IntStream.rangeClosed(1, 20).boxed().collect(Collectors.toList());
問題はCollectors.toList()部分的に発生します。
私の質問は短いのですが、なぜコンパイルできないのですか?
final ArrayList <Integer> list = IntStream.rangeClosed(1, 20).boxed().collect(Collectors.toList());
問題はCollectors.toList()部分的に発生します。
Collectors.toList()である必要のない、おそらくそうではListない実装を返します。ArrayList
試す
final List <Integer> list = IntStream.rangeClosed(1, 20)
.boxed()
.collect(Collectors.toList());
collect(Collectors.toCollection(ArrayList::new))が特に必要な場合に使用できますArrayList。
final ArrayList <Integer> list = IntStream.rangeClosed(1, 20)
.boxed()
.collect(Collectors.toCollection(ArrayList::new));