-
Notifications
You must be signed in to change notification settings - Fork 0
/
LamdaExpressions.java
43 lines (34 loc) · 1.03 KB
/
LamdaExpressions.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.rajpro;
import java.util.ArrayList;
import java.util.Arrays;
import sun.font.CreatedFontTracker;
public class LamdaExpressions {
public static void main(String[] args) {
try {
ArrayList<String> al=new ArrayList<>();
al.add("a");
al.add("b");
al.add("c");
al.forEach( e -> System.out.println( e ) );
System.out.println("-------------------");
al.forEach((String e) -> System.out.println(e));
System.out.println("-----------");
al.forEach(e ->{
System.out.println(e);
System.out.println(e);
});
System.out.println("-----------");
Arrays.asList( "a", "b", "d" ).forEach( e -> System.out.println( e ) );
System.out.println("---------------");
Arrays.asList( "a", "b", "d" ).sort( ( e1, e2 ) -> e1.compareTo( e2 ) );
System.out.println("-------------");
Arrays.asList( "a", "e", "d" ).sort( ( e1, e2 ) -> {
int result = e1.compareTo( e2 );
return result;
} );
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
}