I have a class
class Person {
// get/set omitted for simplicity
public String firstName;
public String lastName;
}
also I have a list of such objects
List<Person> list ...
I need to convert with the streams the following
List<Person> list ...
List<String> firstLastNames = list.stream()....
So my List firstLastNames will contain first and last names in this list. So.
System.out.println(firstLastNames); // will give me -> "John", "Smith", "Jessica", "Jones".. etc.
How about something like this
stream.stream().flatMap(p -> Stream.of(p.firstName, p.lastName)).collect(Collectors.toList());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With