-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMapExample.java
More file actions
32 lines (24 loc) · 893 Bytes
/
Copy pathMapExample.java
File metadata and controls
32 lines (24 loc) · 893 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
package lambda.ex2;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
public class MapExample {
// 고차 함수, 함수를 인자로 받아, 리스트의 각 요소를 반환
public static List<String> map(List<String> list, StringFunction func){
List<String> str = new LinkedList<>();
for (String s : list) {
str.add(func.apply(s));
}
return str;
}
public static void main(String[] args){
List<String> words = List.of("hello", "java", "lambda");
System.out.println("원본 리스트 : " + words);
StringFunction func1 = (s) -> s.toUpperCase();
StringFunction func2 = (s) -> "***"+s+"***";
List<String> map = map(words, func1);
System.out.println(map.toString());
map = map(words, func2);
System.out.println(map.toString());
}
}