forked from DreamCats/java-notes
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTest3.java
More file actions
36 lines (30 loc) · 736 Bytes
/
Test3.java
File metadata and controls
36 lines (30 loc) · 736 Bytes
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
/**
* @program JavaBooks
* @description: foreach
* @author: mf
* @create: 2020/08/04 21:24
*/
package lmd;
import java.util.Arrays;
import java.util.List;
public class Test3 {
public static void main(String[] args) {
// java 7 增强for
List<String> list = Arrays.asList("I", "love", "you", "too");
for (String s : list) {
System.out.println(s);
}
// java 8
list.forEach(System.out::println);
// java 7
for (String s : list) {
if (s.length() > 3)
System.out.println(s);
}
// java 8
list.forEach(s -> {
if (s.length() > 3)
System.out.println(s);
});
}
}