불필요한 객체생성 꺼려짐
: Stream.distinct()은 stream의 중복을 모두 제거합니다.
: Stream.count()는 stream의 사이즈를 리턴합니다.
: 기존의 리스트 크기와 Stream.distinct().count()가 다르다면 리스트에 중복된 요소가 있었다는 것을 의미합니다.
public static void main(String[] args) {
List<Integer> numList = Arrays.asList(1,1,2,3,4,5);
if(numList.size() != numList.stream().distinct().count()){
System.out.println("중복된 요소가 있습니다! 예외 발생시키기");
}
}