September 2019
Intermediate to advanced
816 pages
18h 47m
English
Starting with JDK 8, we can create a Stream from a collection (Collection.stream()) and filter its elements via filter(Predicate p). The filter will only retain those elements that satisfy the given Predicate.
Finally, we collect these elements via the proper collector:
List<Melon> filteredMelons = melons.stream() .filter(t -> t.getWeight() >= 3000) .collect(Collectors.toList());