알고리즘 팁 - 2

정렬 - 내림차순 정렬

int[] arr = {5, 3, 1, 4, 6, 8, 7, 2};
Integer[] intArr = Arrays.stream(arr).boxed.toArray(Integer[]::new);
Arrays.sort(intArr, Comparator.reverseOrder());
int[] arr = {5, 3, 1, 4, 6, 8, 7, 2};
List<Integer> intlist = Arrays.stream(arr).boxed.sorted(Comparator.reverseOrder()).collect(Collectors.toList());

Comparable과 Comparator

public interface Comparable {
    int compareTo(Object o);
}

Comparator

참고: https://gmlwjd9405.github.io/2018/09/06/java-comparable-and-comparator.html