-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStreamStartMain.java
More file actions
36 lines (28 loc) · 1.11 KB
/
Copy pathStreamStartMain.java
File metadata and controls
36 lines (28 loc) · 1.11 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
package stream.start;
import java.util.List;
import java.util.stream.Stream;
public class StreamStartMain {
public static void main(String[] args) {
List<String> names = List.of("Apple", "Banana", "Barry", "Tomato");
// "B" 로 시작하는 이름만 필터 후 대문자로 바꿔서 리스트 수집
Stream<String> stream = names.stream();
List<String> result = stream
.filter(name -> name.startsWith("B"))
.map(s -> s.toUpperCase())
.toList();
System.out.println("=== 외부 반복 ===");
for (String s : result) {
System.out.println(s);
}
System.out.println("=== forEach, 내부 반복 ===");
names.stream()
.filter(name -> name.startsWith("B"))
.map(s -> s.toUpperCase())
.forEach((s)->System.out.println(s));
System.out.println("=== 메서드 참조 ===");
names.stream()
.filter(name -> name.startsWith("B"))
.map(String::toUpperCase)
.forEach(System.out::println);
}
}