collectors tolist 28 29

Solutions on MaxInterview for collectors tolist 28 29 by the best coders in the world

showing results for - "collectors tolist 28 29"
Ian
29 Mar 2020
1import java.util.List;
2import java.util.Arrays;
3import java.util.stream.Collectors;
4
5
6class Person {  
7
8	private String name = "";
9	
10	public static void main(final String args[]) { 
11		List<Person> people = Arrays.asList(new Person("John"),
12											new Person("Jane"),
13											new Person("Max"));
14		List<String> peopleNameWithJ = people.stream()
15			.map(Person::getName)
16			.filter(name -> name.startsWith("J"))
17			.collect(Collectors.toList());
18		System.out.println("Names: " + peopleNameWithJ); 
19	}
20
21	
22	public Person(final String name) {
23		setName(name);
24	}
25
26	
27	public String getName() {
28		return name;
29	}
30	
31	public void setName(final String name) {
32		this.name = name;
33	}
34}