Commit 6bda8bad authored by Trisha Gee's avatar Trisha Gee
Browse files

Final Streamed example

parent 196dcb7b
Loading
Loading
Loading
Loading
+12 −3
Changes for src/main/java/ch10c/LimitWithStream.java: 12 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -9,9 +9,9 @@ public class LimitWithStream {
  public static void main(String[] args) {
    List<String> strings = List.of("I", "am", "a", "list", "of", "Strings");

    Stream<String> stream = strings.stream();
    Stream<String> limit = stream.limit(4);
    List<String> result = limit.collect(Collectors.toList());
    List<String> result = strings.stream()
                                 .limit(4)
                                 .collect(Collectors.toList());
    System.out.println("result = " + result);
  }

@@ -38,4 +38,13 @@ public class LimitWithStream {
    List<String> result = limit.collect(Collectors.toList());
    System.out.println("result = " + result);
  }

  void limitAsStream() {
    List<String> strings = List.of("I", "am", "a", "list", "of", "Strings");

    List<String> result = strings.stream()
                                 .limit(4)
                                 .collect(Collectors.toList());
    System.out.println("result = " + result);
  }
}