반응형
max
-
[JAVA] JAVA8 스트림 Max&Min 사용 방법자바/자바8 2020. 9. 17. 11:39
이번 시간에는 Stream API를 이용해서 주어진 collection에서 max & min 값을 찾아내는 방법에 대해서 알아보도록 하겠습니다. Integer 리스트에서 Max 값 찾기 @Test public void testFindMaxValueInIntegerList() throws Exception { // given Integer expectedResult = 70; List listOfIntegers = Array.asList(4, 9, 1, 10, 48, 70); // when Integer max = listOfIntegers .stream() // 리스트 객체에서 스트림을 얻어오는 함수 .mapToInt(v -> v) // Integer 스트림을 얻어오는 함수 .max() // max 값을..