You can group List
by the speed of each object and count the number of occurrences. Assuming your object is of type MyClass
:
Map<String, Long> map = myList.stream().collect(groupingBy(MyClass::getRate, counting()));
Map
, - , - , . "Low"
, "Medium"
"High"
.
groupingBy(classifier, downstream)
, ( MyClass::getRate
) ( counting()
).
NB: :
import static java.util.stream.Collectors.counting;
import static java.util.stream.Collectors.groupingBy;