Repository navigation
Expand file tree
/
Copy pathLambdaTest.java
More file actions
52 lines (46 loc) · 1.56 KB
/
Copy pathLambdaTest.java
File metadata and controls
52 lines (46 loc) · 1.56 KB
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
44
45
46
47
48
49
50
51
52
package com.duweri.interview;
import java.awt.Button;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* JAVA8
* @author ¶Åΰ
*/
public class LambdaTest {
public static void main(String[] args) {
}
public void inInterface(){
Button button = new Button();
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("java7");
}
});
// button.addActionListener(e->{System.out.println("java8");})
}
//ν´Ê
public void PredicateDemo(){
// List<String> names = Arrays.asList("Alice", "Bob", "Charlie", "Dave");
// List<String> filteredNames = names
// .filter(e -> e.length() >= 4)
// .into(new ArrayList<String>());
// for (String name : filteredNames) {
// System.out.println(name);
// }
// List<String> names = Arrays.asList("Alice", "Bob", "Charlie", "Dave");
// names.filter(e -> e.length() >= 4)
// .forEach(e -> { System.out.println(e); });
//==================================================
// List<String> names = Arrays.asList("Alice", "Bob", "Charlie", "Dave");
// names.mapped(e -> { return e.length(); })
// .asIterable() // returns an Iterable of BiValue elements
// // an element's key is the person's name, its value is the string length
// .filter(e -> e.getValue() >= 4)
// .sorted((a, b) -> a.getValue() - b.getValue())
// .forEach(e -> { System.out.println(e.getKey() + '\t' + e.getValue()); });
}
}