Open dongur2 opened 2 months ago
같은 타입 객체들 을 비교하여 '오름차순으로 정렬(natural order)'하는 전략을 정의하는 인터페이스
@Override public int compareTo(T param) { return Integer.compare(x, y); }
Integer.compare(x, y) 메서드의 리턴값으로 정렬
Integer.compare(x, y)
compare(arg1, arg2) 메서드를 정의하여 다른 타입 객체들 을 비교해 정렬할 수 있는 더 유연한 인터페이스
compare(arg1, arg2)
@Override public int compare(arg1, arg2) { return Integer.compare(x, y); }
https://www.baeldung.com/java-comparator-comparable
프로그래머스/1/12915. 문자열 내 마음대로 정렬하기
public int compareTo(String param)
Comparable
같은 타입 객체들 을 비교하여 '오름차순으로 정렬(natural order)'하는 전략을 정의하는 인터페이스
Integer.compare(x, y)
메서드의 리턴값으로 정렬Comparator
compare(arg1, arg2)
메서드를 정의하여 다른 타입 객체들 을 비교해 정렬할 수 있는 더 유연한 인터페이스https://www.baeldung.com/java-comparator-comparable