Java Reference
In-Depth Information
I will show many examples of performing aggregate operations on different types of streams. Most of the time,
it is will be easier to explain the stream operations using streams of numbers and strings. I will show some real world
examples of using streams by using a stream of Person objects. Listing 13-2 contains the declaration for the Person class.
Listing 13-2. A Person Class
// Person.java
package com.jdojo.streams;
import java.time.LocalDate;
import java.time.Month;
import java.util.Arrays;
import java.util.List;
public class Person {
// An enum to represent the gender of a person
public static enum Gender {MALE, FEMALE}
private long id;
private String name;
private Gender gender;
private LocalDate dob;
private double income;
public Person(long id, String name, Gender gender,
LocalDate dob, double income) {
this.id = id;
this.name = name;
this.gender = gender;
this.dob = dob;
this.income = income;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
 
Search WWH ::




Custom Search