File tree Expand file tree Collapse file tree
src/main/java/com/superthirty Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package com .superthirty ;
2+
3+ import java .util .List ;
4+
5+ public class AllEmployeesHavingEmailQ6 {
6+ public static void main (String [] args ) {
7+ List <Employee > employees = EmployeeDTO .getEmployees ();
8+ boolean isAllHaivngEmail = employees .stream ().allMatch (x -> x .getEmail () != null );
9+ employees .stream ().filter (x -> x .getEmail () == null ).forEach (System .out ::println );
10+ System .out .println (isAllHaivngEmail );
11+ }
12+ }
Original file line number Diff line number Diff line change 1+ package com .superthirty ;
2+
3+ import java .util .List ;
4+
5+ public class EmailActiveEmployeeQ7 {
6+ public static void main (String [] args ) {
7+ List <Employee > employees = EmployeeDTO .getEmployees ();
8+ employees .stream ().filter (x -> x .isActive ()).map (Employee ::getName ).forEach (System .out ::println );
9+ }
10+ }
Original file line number Diff line number Diff line change 1+ package com .superthirty ;
2+
3+ import java .util .Comparator ;
4+ import java .util .List ;
5+ import java .util .Optional ;
6+
7+ public class HighestSalary {
8+ public static void main (String [] args ) {
9+ List <Employee > employees = EmployeeDTO .getEmployees ();
10+ //First Approach Using sorted and findFirst
11+ String result = employees .stream ()
12+ .sorted (Comparator .comparing (Employee ::getSalary ).reversed ())
13+ .map (Employee ::getName ).toList ().stream ().findFirst ().orElse (null );
14+ System .out .println (result );
15+ //Second Approach Using max
16+
17+ Optional <Employee > resultUsinngMax = employees .stream ().max (Comparator .comparingDouble (Employee ::getSalary ));
18+ System .out .println (resultUsinngMax );
19+ }
20+ }
You can’t perform that action at this time.
0 commit comments