diff --git a/src/main/java/RandomDemo.java b/src/main/java/RandomDemo.java index 90af96c..75bae4e 100644 --- a/src/main/java/RandomDemo.java +++ b/src/main/java/RandomDemo.java @@ -1,13 +1,19 @@ import java.util.OptionalInt; import java.util.Random; +import java.util.stream.DoubleStream; import java.util.stream.IntStream; public class RandomDemo { + @SuppressWarnings("SimplifyStreamApiCallChains") public static void main(String[] args) { + DoubleStream.generate(Math::random) + .limit(10) + .forEach(System.out::println); + Random r = new Random(); int sum = IntStream.generate(() -> r.nextInt(10)) .limit(10) - .map(n -> { + .map(n -> { // this is the peek method System.out.println("n = " + n); return n; }) @@ -22,6 +28,7 @@ public static void main(String[] args) { .peek(System.out::println) .filter(n -> n > 7) .findFirst(); + System.out.println(first); } } diff --git a/src/main/java/lambdas/UsePerson.java b/src/main/java/lambdas/UsePerson.java index 343912d..3fcd32d 100644 --- a/src/main/java/lambdas/UsePerson.java +++ b/src/main/java/lambdas/UsePerson.java @@ -28,6 +28,7 @@ public static void main(String[] args) { // .map(Person::new) // uses the Person(Person) ctr -> Stream .collect(Collectors.toList()); System.out.println(people); + System.out.println(people.getClass().getName()); Person[] peopleArray = names.stream() .map(Person::new) diff --git a/src/main/java/streams/FlatMapDemo.java b/src/main/java/streams/FlatMapDemo.java index c8186dc..ea076d0 100644 --- a/src/main/java/streams/FlatMapDemo.java +++ b/src/main/java/streams/FlatMapDemo.java @@ -44,7 +44,7 @@ public static void main(String[] args) { // stream() on an empty collection already returns an empty stream customers.stream() .flatMap(customer -> - customer.getOrders().size() == 0 ? Stream.empty() : + customer.getOrders().isEmpty() ? Stream.empty() : customer.getOrders().stream()) .forEach(System.out::println);