이 검사는 다음의 호출 체인을 대체합니다.
collection.stream().forEach() → collection.forEach()collection.stream().collect(toList/toSet/toCollection()) → new CollectionType<>(collection)collection.stream().toArray() → collection.toArray()Arrays.asList().stream() → Arrays.stream() 또는 Stream.of()IntStream.range(0, array.length).mapToObj(idx -> array[idx]) → Arrays.stream(array)IntStream.range(0, list.size()).mapToObj(idx -> list.get(idx)) → list.stream()Collections.singleton().stream() → Stream.of()Collections.emptyList().stream() → Stream.empty()stream.filter().findFirst().isPresent() → stream.anyMatch()stream.collect(counting()) → stream.count()stream.collect(maxBy()) → stream.max()stream.collect(mapping()) → stream.map().collect()stream.collect(reducing()) → stream.reduce()stream.collect(summingInt()) → stream.mapToInt().sum()stream.mapToObj(x -> x) → stream.boxed()stream.map(x -> {...; return x;}) → stream.peek(x -> ...)!stream.anyMatch() → stream.noneMatch()!stream.anyMatch(x -> !(...)) → stream.allMatch()stream.map().anyMatch(Boolean::booleanValue) → stream.anyMatch()IntStream.range(expr1, expr2).mapToObj(x -> array[x]) → Arrays.stream(array, expr1, expr2)Collection.nCopies(count, ...) → Stream.generate().limit(count)stream.sorted(comparator).findFirst() → Stream.min(comparator)optional.orElseGet(() -> { throw new ...; }) → optional.orElseThrow()
일부 경우에는 대체의 의미가 조금 다를 수 있습니다. 예를 들어, Collections.synchronizedList(...).stream().forEach()는 동기화되지 않으나 Collections.synchronizedList(...).forEach()는 동기화됩니다.
또한 결과 요소가 null인 경우 collect(Collectors.maxBy())는 빈 Optional을 반환하나 이러한 경우 Stream.max()는 NullPointerException을 던집니다.