Skip to content

Commit 1596e0d

Browse files
committed
unary and binary fucntions
1 parent 58d3668 commit 1596e0d

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,14 @@ This repository contain all the Java 8 related concepts and examples.
1010
2. BiConsumer andthen
1111
3. Predicate : and or negate
1212
fucntiona and then
13+
biFucntion
14+
unary
15+
binaary
16+
supplier
1317

1418

19+
Method reference
20+
1521
* The lambda variable name and the local variable names cannot be same.
1622
* The local variables cannot be modified inside lambda expressions.
1723
* No restrictions for instance variables.
1.49 KB
Binary file not shown.

bin/revise/lambdas/StringConcat.class

687 Bytes
Binary file not shown.

src/revise/lambdas/LambdasExamples1.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,23 @@
66
import java.util.Optional;
77
import java.util.UUID;
88
import java.util.function.BiConsumer;
9+
import java.util.function.BinaryOperator;
910
import java.util.function.Consumer;
1011
import java.util.function.Function;
1112
import java.util.function.Predicate;
13+
import java.util.function.UnaryOperator;
1214
import java.util.stream.Collectors;
1315
import java.util.stream.Stream;
1416

1517
import data.Student;
1618
import data.StudentDB;
1719

20+
class StringConcat {
21+
public static String concat(String x, String y) {
22+
return "Name : " + x + " Gender : " + y;
23+
}
24+
}
25+
1826
public class LambdasExamples1 {
1927
public static void main(String args[]) {
2028
example1(10);
@@ -24,9 +32,29 @@ public static void main(String args[]) {
2432
example5();
2533
example6();
2634
example7();
35+
example8();
36+
example9();
2737

2838
}
2939

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+
3058
public static void example7() {
3159
System.out.println("List all names");
3260
List<Student> listStudents = StudentDB.getAllStudents();

0 commit comments

Comments
 (0)