-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFilteringExample.java
More file actions
29 lines (26 loc) Β· 982 Bytes
/
FilteringExample.java
File metadata and controls
29 lines (26 loc) Β· 982 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
package ch17.sec05;
import java.util.ArrayList;
import java.util.List;
public class FilteringExample {
public static void main(String[] args) {
// List 컬λ μ
μμ±
List<String> list = new ArrayList<>();
list.add("μ΄λ¦1");
list.add("κΈ°λ¦2");
list.add("μ΄λ¦1");
list.add("μ΄λ¦3");
list.add("μλ¦4");
// μ€λ³΅ μμ μ κ±°
list.stream().distinct().forEach(System.out::println);
System.out.println();
// μ΄λ‘ μμνλ μμλ§ νν°λ§
// startsWith() : μ£Όμ΄μ§ λ¬Έμμ΄λ‘ μμνλ©΄ true, μλλ©΄ false
list.stream().filter(n -> n.startsWith("μ΄"))
.forEach(System.out::println);
System.out.println();
// μ€λ³΅ μμ μ κ±° ν μ΄λ‘ μμνλ μμλ§ νν°λ§
list.stream().distinct()
.filter(n -> n.startsWith("μ΄"))
.forEach(System.out::println);
}
}