List<Integer> 로부터 최댓값 탐색
int maxValue = list.get(0);
for (int value : list) {
maxValue = Math.max(maxValue, value);
}
int maxValue = list.stream()
.max(Comparator.comparingInt(e -> e)) // .map((e1, e2) -> e1 - e2)
.get();
int maxValue = list.stream()
.max(Comparator.comparingInt(e -> e)) // .map((e1, e2) -> e1 - e2)
.orElse(-1);
비교 연산에 따라 최댓값을 추출
Optional 객체를 반환
Optional 객체로부터 값을 읽어오는 메소드
값이 없다면 예외가 발생할 수 있음
Optional 객체에 값이 없을 경우 기본 값을 설정