forked from janbodnar/Java-Advanced
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaStreamMapEx5.java
More file actions
24 lines (17 loc) · 791 Bytes
/
JavaStreamMapEx5.java
File metadata and controls
24 lines (17 loc) · 791 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package com.zetcode;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
public class JavaStreamMapEx5 {
public static void main(String[] args) {
var users = List.of(new User("Peter", "programmer"),
new User("Jane", "accountant"), new User("Robert", "teacher"),
new User("Milan", "programmer"), new User("Jane", "designer"));
var userNames = users.stream().map(user -> user.getName()).sorted()
.collect(Collectors.toList());
System.out.println(userNames);
var occupations = users.stream().map(user -> user.getOccupation())
.sorted(Comparator.reverseOrder()).distinct().collect(Collectors.toList());
System.out.println(occupations);
}
}