Let's say I have such object:
public class Customer {
private Integer id;
private String country;
private Integer customerId;
private String name;
private String surname;
private Date dateOfBirth;
}
and I have a List<Customer>. I would like to split such list with Java streams so that I would get a list of ids List<Integer>, countries List<String>, customerIds List<Integer> etc.
I know that I could do it as simple as making 6 streams such as:
List<Integer> idsList = customerList.stream()
.map(Customer::getId)
.collect(Collectors.toList());
but doing it that many times that I have fields seems pretty dull. I was thinking about custom Collector but I could not come up with anything useful that would be both neat and efficient.
forEachadding to respective lists would be better choice