@@ -14,64 +14,58 @@ public class AdvanceCollectors {
1414public static void main (String [] args ) {
1515
1616List <Student > students = JavaInputFixture .createList ();
17- // joiningCollector(students);
18- // summaryStatisticsCollector(students);
19- // partitioningByCollector(students);
20- // groupingByCollector(students);
17+ joiningCollector (students );
18+ summaryStatisticsCollector (students );
19+ partitioningByCollector (students );
20+ groupingByCollector (students );
2121mappingByCollector (students );
2222}
2323
2424private static void joiningCollector (List <Student > students ) {
2525System .out .println ("######## Executing joiningCollector() : ######## " );
26- String allStudents = students .stream ()
27- .map (Student ::getName )
28- .collect (Collectors .joining (" | " ));
29- System .out .println ("Collectors.joining() : " +allStudents );
26+ String allStudents = students .stream ().map (Student ::getName ).collect (Collectors .joining (" | " ));
27+ System .out .println ("Collectors.joining() : " + allStudents );
3028System .out .println ("######## Ending the execution of joiningCollector() ######## " );
31-
29+
3230}
33-
31+
3432private static void summaryStatisticsCollector (List <Student > students ) {
3533System .out .println ("######## Executing summaryStatisticsCollector() : ######## " );
36- DoubleSummaryStatistics statistics = students .stream ()
37- .mapToDouble (Student ::getAge )
38- .summaryStatistics ();
39-
40- System .out .println ("summaryStatistics() : " +statistics );
41- System .out .println ("Total Count : " +statistics .getCount ());
34+ DoubleSummaryStatistics statistics = students .stream ().mapToDouble (Student ::getAge ).summaryStatistics ();
35+
36+ System .out .println ("summaryStatistics() : " + statistics );
37+ System .out .println ("Total Count : " + statistics .getCount ());
4238System .out .println ("Total Sum : " + statistics .getSum ());
4339System .out .println ("Minimum Age : " + statistics .getMin ());
4440System .out .println ("Maximum Age : " + statistics .getMax ());
4541System .out .println ("Average Age : " + statistics .getAverage ());
4642System .out .println ("######## Ending the execution of summaryStatisticsCollector() ######## " );
4743}
48-
44+
4945private static void partitioningByCollector (List <Student > students ) {
5046System .out .println ("######## Executing partitioningByCollector() : ######## " );
51- Map <Boolean ,List <Student >> partition = students .stream ()
47+ Map <Boolean , List <Student >> partition = students .stream ()
5248.collect (Collectors .partitioningBy (stud -> stud .getCity ().equals ("Pune" )));
53-
54- System .out .println ("Students living in Pune : " + partition .get (true ));
55- System .out .println ("Students not living in Pune : " + partition .get (false ));
49+
50+ System .out .println ("Students living in Pune : " + partition .get (true ));
51+ System .out .println ("Students not living in Pune : " + partition .get (false ));
5652System .out .println ("######## Ending the execution of partitioningByCollector() ######## " );
5753}
58-
54+
5955private static void groupingByCollector (List <Student > students ) {
6056System .out .println ("######## Executing groupingByCollector() : ######## " );
61- Map <String ,List <Student >> groupBy = students .stream ()
62- .collect (Collectors .groupingBy (Student ::getCity ));
63-
64- System .out .println ("groupingByCollector : " +groupBy );
57+ Map <String , List <Student >> groupBy = students .stream ().collect (Collectors .groupingBy (Student ::getCity ));
58+
59+ System .out .println ("groupingByCollector : " + groupBy );
6560System .out .println ("######## Ending the execution of groupingByCollector() ######## " );
6661}
6762
6863private static void mappingByCollector (List <Student > students ) {
6964System .out .println ("######## Executing mappingByCollector() : ######## " );
70- Map <String ,Set <String >> mappingBy = students .stream ()
71- .collect (Collectors .groupingBy (Student ::getCity ,
72- Collectors .mapping (Student ::getName , Collectors .toSet ())));
73-
74- System .out .println ("mappingByCollector : " +mappingBy );
65+ Map <String , Set <String >> mappingBy = students .stream ().collect (
66+ Collectors .groupingBy (Student ::getCity , Collectors .mapping (Student ::getName , Collectors .toSet ())));
67+
68+ System .out .println ("mappingByCollector : " + mappingBy );
7569System .out .println ("######## Ending the execution of mappingByCollector() ######## " );
7670}
7771}
0 commit comments