-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObjectJoin.java
More file actions
55 lines (42 loc) · 1.17 KB
/
Copy pathObjectJoin.java
File metadata and controls
55 lines (42 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package java8.join;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collector;
import java.util.stream.Collectors;
/**
* @Author : yion
* @Date : 2016. 8. 22.
* @Description :
*/
public class ObjectJoin {
static List<Game> list = Arrays.asList(
new Game("Dragon Blaze", 5),
new Game("Angry Bird", 5),
new Game("Candy Crush", 5)
);
public static void main(String[] args) {
String result = list.stream().map(x -> x.getName())
.collect(Collectors.joining(",", "{", "}"));
System.out.println("result = " + result); // {Dragon Blaze, Angry Bird, Candy Crush}
}
private static class Game {
String name;
int ranking;
public Game(String name, int ranking) {
this.name = name;
this.ranking = ranking;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getRanking() {
return ranking;
}
public void setRanking(int ranking) {
this.ranking = ranking;
}
}
}