Some examples of using various Java Streams facilities, lambdas and functional interfaces to process various sets of data:
- English Premier League football results from 2016-17 (source)
- 2017 UK General Election results (source)
- example series generators including the Fibonacci series, factorial series and prime number series
Stream facilities demonstrated include:
- stream generation operations:
- stream() - for Collection-based objects
- IntStream.rangeClosed()
- Stream.iterate()
- Stream.generate()
- Stream.empty()
- Stream.of()
- Stream.builder()
- Stream.concat()
- Arrays.stream()
- Files.lines()
- String.chars()
- intermediate stream processing operations:
- limit()
- skip()
- peek()
- filter()
- map(), mapToObj() - an IntStream method
- flatMap()
- distinct()
- sorted()
- parallel(), sequential()
- terminal stream operations:
- forEachOrdered(), forEach()
- count(), min(), max()
- sum(), average(), summaryStatistics() - IntStream methods
- allMatch(), anyMatch(), noneMatch()
- findAll(), findAny()
- collect()
- stream Collectors operations:
- Collectors.toList() and .toSet()
- Collectors.summingInt()
- Collectors.averagingInt()
- Collectors.maxBy() and .minBy()
- Collectors.counting()
- Collectors.joining()
- Collectors.groupingBy()
- Collectors.partitioningBy()
- Collectors.reducing()
- Collectors.toMap()
- Collectors.toCollection()
- Collectors.collectingAndThen()
- and also a bespoke Collector generated by calling Collector.of() with a class implementing Supplier, BiConsumer and BinaryOperator interfaces
The examples also include cases of:
- a Predicate object
- including a use of its .or() method
- a UnaryOperator object (extends Function)
- a Supplier object
- a Comparator object, created using the combination of:
- Comparator.comparing()
- thenComparing()
- reversed()
- a Comparator object, created using a lambda expression
- the Objects object
- BigInteger and BigDecimal objects
- Optional objects