Skip to content

Commit 8c1e6f4

Browse files
add Collectors Demo
1 parent ea27c88 commit 8c1e6f4

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package FDynamic.Stream;
2+
3+
import java.math.BigDecimal;
4+
import java.util.ArrayList;
5+
import java.util.Arrays;
6+
import java.util.List;
7+
import java.util.Map;
8+
import java.util.stream.Collectors;
9+
10+
public class CollectorsDemo {
11+
12+
public static void main(String[] args) {
13+
List<Person> personList= Arrays.asList(
14+
new Person("aaa", 18, new BigDecimal(123)),
15+
new Person("aaa", 18, new BigDecimal(123)),
16+
new Person("bbb", 19, new BigDecimal(124))
17+
);
18+
groupBy(personList);
19+
}
20+
21+
/**
22+
* 根据人员的name来进行分组
23+
* @param personList
24+
*/
25+
public static void groupBy(List<Person> personList){
26+
Map<String, List<Person>> map=personList.stream()
27+
.collect(Collectors.groupingBy(Person::getName));
28+
System.out.println(map);
29+
}
30+
31+
}

0 commit comments

Comments
 (0)