When you convert a Stream Object into a List Object,
Why
numbers
.filter(number -> number > 0)
.collect(Collector.toList());
does not work?
Whisper
Level 31
Why Collector keyword is ignored?
Under discussion
Comments (4)
- Popular
- New
- Old
You must be signed in to leave a comment
Guadalupe Gagnon
15 August 2022, 13:54
Or are you asking why you have to use toList() instead of Collectors.toList()? These bits of code are exactly the same but you need a static import such as:
To simply use toList() without typing Collectors. What do the task conditions say you have to do? 0
Whisper
15 August 2022, 13:58
I have never noticed this piece of code..... my bad....
but the condition says to call a static toList() method of the Collector class.
0
Thomas
16 August 2022, 06:44
Collectors.toList()
Some hints:
0
Guadalupe Gagnon
15 August 2022, 13:45
Did you convert the Stream to a List of numbers such as List<Integer>? If not then you have a List<Object> and you will not be able to compare an Object with 0.
0