스트림의 최종연산 가. reduce() Stream의 데이터를 더하거나 빼는 등 사칙연산을 사용하여 하나의 값으로 출력한다. 예제 : 1~10까지의 값을 모두 더하는 방법이다. IntStream intStream = IntStream.rangeClosed(1, 10); int num = intStream.reduce((x, y)-> x+y) .orElse(0); 연산을 하기에 초기값 설정을 해준다. 연산을 하기에 초기값 설정 방법은 2가지가 있다. 첫번째 : orElse IntStream intStream2 = IntStream.rangeClosed(1, 10); int num = intStream.reduce((x, y)-> x+y) .orElse(0); System.out.println(num); /..

[자바의 정석 - 기초편] ch 14~17~22 스트림 만들기 1. 컬렉션을 스트림으로 변환하기 Collection인터페이스의 stream()을 통하여 변환한다. 아래와 같이 Collection.java 안에는 stream메서드가 존재한다. Stream stream() // Collection인터페이스의 메서드 예제 Collection인 인터페이스의 stream을 사용하여 stream변환 List list = Arrays.asList(1,2,3,4,5); // list를 데이터소스로 하는 새로운 스트림을 생성한다. Stream intStream = list.stream(); intStream.forEach(System.out::print); //stream has already been opera..
- Total
- Today
- Yesterday
- AnnotationConfigApplicationContext
- install
- JPA
- 중간연산
- NPM
- 람다
- MAC
- webpack
- 차이
- 자바8
- springboot
- Intellij
- vscode
- ngnix
- 영속성 컨텍스트
- container
- Vuex
- 스트림
- docker
- stream
- lambda
- nginx
- ApplicationContext
- java
- map
- 최종연산
- BeanFactory
- Vue
- elasticsearch
- mvn
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |