forked from coderbruis/JavaSourceCodeLearning
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLambdaTest3.java
More file actions
33 lines (25 loc) · 876 Bytes
/
LambdaTest3.java
File metadata and controls
33 lines (25 loc) · 876 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
package com.learnjava.java8;
import java.util.Arrays;
import java.util.List;
public class LambdaTest3 {
/**
* Stream实例
* @param args
*/
public static void main(String[] args) {
List<String> strings = Arrays.asList("abc", "", "bc", "efg", "abcd", "", "jkl");
strings.stream() //创建流
.filter(s -> s.startsWith("a"))
.map(String::toUpperCase) //转换成大写 String::toUpperCase 等同于 string -> string.toUpperCase()
.sorted() //排序
.forEach(System.out::println); // for循环打印
strings.stream()
.filter(s -> s.startsWith("a"))
.map(s -> s.toUpperCase())
.map(String::toUpperCase)
.sorted()
.forEach(System.out::println);
// C1
// C2
}
}