I am new to Java8 streams and was playing around with them. I was following this talk by Venkat Subramaniam Programming with Streams in Java 8 and coding it.
I called .stream() twice one after another got the following results:-
- get, in uppercase, the names of all female older than 18
[SARA, SARA, PAULA]
- print all males
basicCode.Person@c39f790
basicCode.Person@71e7a66b
- Am I missing something in my code? Why I am getting object addresses? toString() was missing in the class
- Can I call .stream() immediately after the previous .stream() YES we can
I am doing the following:-
List <Person> people = createPeople(); // creating objects
    System.out.println("1. get, in uppercase, the names of all female older than 18");
    System.out.println( 
            people.stream()
            .filter(person -> person.getGender() == Gender.FEMALE)
            .filter(person -> person.getAge() > 18)
            .map(person -> person.getName().toUpperCase())              
            .collect(toList())
            );
            System.out.println("2. print all males");
            people.stream()
            .filter(p -> p.getGender() == Gender.MALE)
            .forEach(System.out::println);
public class Person {
private final String name;
private final Gender gender; //is an enum {MALE, FEMALE}
private final int age;
}
 
     
     
    