• 코드:
​x
 
1
import java.util.stream.*;
2
​
3
public class prog {
4
    public static void main(String[] args){
5
        IntStream stream1 = IntStream.of(7, 5, 5, 2, 1, 2, 3, 5, 4, 6);
6
        IntStream stream2 = IntStream.of(7, 5, 5, 2, 1, 2, 3, 5, 4, 6);
7
        
8
        // 스트림에서 중복된 요소를 제거함.
9
        stream1.distinct().forEach(e -> System.out.print(e + " "));
10
        System.out.println();
11
        
12
        // 스트림에서 홀수만을 골라냄.
13
        stream2.filter(n -> n % 2 != 0).forEach(e -> System.out.print(e + " "));
14
    }
15
}
표준입력 & 실행옵션