-
[Stream] int 숫자 배열을 filter를 통해서 내림차순으로 정렬하기자바/자바8 2021. 4. 22. 22:02
int[] A = new int[]{3, 2, -2, 5, -3}; int[] positives = IntStream.of(A).boxed().sorted(Comparator.reverseOrder()) .filter(o -> o >= 0) .mapToInt(i -> i) .toArray(); int[] negatives = IntStream.of(A).boxed().sorted(Comparator.reverseOrder()) .filter(o -> o < 0) .mapToInt(i -> i) .toArray(); for(int value : positivies) { if(IntStream.of(negatives).anyMatch(o -> o == -value)) return value; }
'자바 > 자바8' 카테고리의 다른 글
[JAVA] Streams를 이용한 Map Collection 사용 방법 (0) 2021.01.20 [JAVA] JAVA8 스트림 Max&Min 사용 방법 (1) 2020.09.17