Other Operations
Remove Duplicates
final Collection<Object> filtered;
filtered = originalStream.distinct().collect(Collectors.toList());Sorting
final Collection<Object> sorted;
sorted = originalStream.sorted().collect(Collectors.toList());Min and Max
final Object value;
value = originalStream.min(comparator);final Object value;
value = originalStream.max(comparator);Numeric Ranges
final Iterable<Short> years;
years = IntStream.range(startYear, endYear + 1).mapToObj(i -> (short) i).collect(Collectors.toList());final Iterable<Short> years;
years = IntStream.rangeClosed(startYear, endYear).mapToObj(i -> (short) i).collect(Collectors.toList());Limiting Size
Stream<Integer> stream;
// Numbers 1 to 10
stream = Stream.iterate(1, n -> n).limit(10);Skipping Values
Stream<Integer> stream;
// Numbers 5 to 10
stream = Stream.iterate(1, n -> n).skip(4).limit(10);Last updated
Was this helpful?