Arrays stream

Arrays.asList(5,3,4,7,2).stream(); // 스트림 생성
Arrays.asList(5,3,4,7,2).stream().forEach(System.out::println);
Arrays.asList(5,3,4,7,2).stream().map(i-> i*i).forEach(System.out::println);
Arrays.asList(5,3,4,7,2).stream().filter(i-> i>3).forEach(System.out::println);
int sum = Arrays.asList(5,3,4,7,2).stream().reduce((i, j) -> i+j).get(); // ((((5+3)+4)+7)+2)
System.out.println(“sum=” + sum);
List<Integer> intList = Arrays.asList(5,3,4,7,2).stream().filter(i-> i>3).collect(Collectors.toList());
intList.forEach(System.out::println);
int result = Arrays.asList(5,3,4,7,2).stream().filter(i-> i>3).findFirst().orElse(null); // 3보다 큰 첫번째 요소 반환
System.out.println(“result=” + result);
Arrays.asList(5,3,4,7,2).stream().filter(i-> i>3).findAny().ifPresent(System.out::println); // 3보다 큰 요소 반환
boolean result2 = Arrays.asList(5,3,4,7,2).stream().allMatch(i-> i>0); // 모두다 0보다 큰지
System.out.println(“result2=” + result2);