-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCollectExample.java
More file actions
29 lines (24 loc) ยท 1.04 KB
/
CollectExample.java
File metadata and controls
29 lines (24 loc) ยท 1.04 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
package ch17.sec12.exam02;
import ch17.sec12.exam01.Student;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class CollectExample {
public static void main(String[] args) {
List<Student> totalList = new ArrayList<>();
totalList.add(new ch17.sec12.exam01.Student("ํ", "๋จ", 92));
totalList.add(new ch17.sec12.exam01.Student("๊น", "์ฌ", 87));
totalList.add(new ch17.sec12.exam01.Student("๊ฐ", "๋จ", 95));
totalList.add(new ch17.sec12.exam01.Student("์ค", "์ฌ", 93));
Map<String, Double> map = totalList.stream()
.collect(
// ๊ทธ๋ฃนํ ํ ๋งคํ ๋ฐ ์ง๊ณ๋ฅผ ์ํํ ์ ์๋๋ก ๋๋ฒ์งธ Collector๋ฅผ ๊ฐ์ง ์ ์๋ค.
Collectors.groupingBy(
a -> a.getSex(),
Collectors.averagingDouble(a -> a.getScore())
)
);
System.out.println("map = " + map);
}
}