File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed
Modern-Java-Examples/src/com/learn/streams Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change 11package com .learn .streams ;
22
3+ import com .learn .data .Student ;
4+ import com .learn .data .StudentDataBase ;
5+
36import java .util .ArrayList ;
47import java .util .List ;
58import java .util .Optional ;
@@ -18,6 +21,11 @@ public static void main(String[] args) {
1821 Optional <Integer > result2 = perfromMultiplicationWithoutIdentity (new ArrayList <>());
1922 System .out .println (result2 .isPresent ());
2023
24+ Optional <Student > highestGpaStudent = getHightestGPAStudent ();
25+ if (highestGpaStudent .isPresent ()) {
26+ System .out .println (highestGpaStudent .get ());
27+ }
28+
2129 }
2230
2331 /**
@@ -42,4 +50,15 @@ public static Optional<Integer> perfromMultiplicationWithoutIdentity(List<Intege
4250 return integerList .stream ()
4351 .reduce ((num1 , num2 ) -> num1 * num2 );
4452 }
53+
54+ /**
55+ * <p>
56+ * Find the Student with highest GPA
57+ * </p>
58+ * @return
59+ */
60+ public static Optional <Student > getHightestGPAStudent () {
61+ return StudentDataBase .getAllStudents ().stream ()
62+ .reduce ((student1 , student2 ) -> student1 .getGpa () > student2 .getGpa () ? student1 : student2 );
63+ }
4564}
You can’t perform that action at this time.
0 commit comments