6
6
import java .util .Optional ;
7
7
import java .util .UUID ;
8
8
import java .util .function .BiConsumer ;
9
+ import java .util .function .BinaryOperator ;
9
10
import java .util .function .Consumer ;
10
11
import java .util .function .Function ;
11
12
import java .util .function .Predicate ;
13
+ import java .util .function .UnaryOperator ;
12
14
import java .util .stream .Collectors ;
13
15
import java .util .stream .Stream ;
14
16
15
17
import data .Student ;
16
18
import data .StudentDB ;
17
19
20
+ class StringConcat {
21
+ public static String concat (String x , String y ) {
22
+ return "Name : " + x + " Gender : " + y ;
23
+ }
24
+ }
25
+
18
26
public class LambdasExamples1 {
19
27
public static void main (String args []) {
20
28
example1 (10 );
@@ -24,9 +32,29 @@ public static void main(String args[]) {
24
32
example5 ();
25
33
example6 ();
26
34
example7 ();
35
+ example8 ();
36
+ example9 ();
27
37
28
38
}
29
39
40
+ public static void example9 () {
41
+ System .out .println ("Binary Functions" );
42
+ List <Student > listStudents = StudentDB .getAllStudents ();
43
+ BinaryOperator <String > binaryOperator = StringConcat ::concat ;
44
+ listStudents .forEach (s -> {
45
+ System .out .println (binaryOperator .apply (s .getName (), s .getGender ()));
46
+ });
47
+ }
48
+
49
+ public static void example8 () {
50
+ System .out .println ("Unary Functions" );
51
+ List <Student > listStudents = StudentDB .getAllStudents ();
52
+ UnaryOperator <String > unaryOperator = String ::toUpperCase ;
53
+ listStudents .forEach (s -> {
54
+ System .out .println (unaryOperator .apply (s .getName ()));
55
+ });
56
+ }
57
+
30
58
public static void example7 () {
31
59
System .out .println ("List all names" );
32
60
List <Student > listStudents = StudentDB .getAllStudents ();
0 commit comments