BACK/JAVA
[JAVA] Collection 최솟값, 최댓값 구하기
연듀
2023. 4. 5. 20:51
기본타입(Primitive type)으로 구성된 컬렉션의 경우
최소, 최대 요소를 찾으려면 Collections.min()이나 Collections.max() 메서드를 사용하면 된다.
List<Integer> list = List.of(1, 2, 3, 4, 5);
Integer min = Collections.min(list); // 1
Integer max = Collections.max(list); // 5
반응형