1. CLASSNAME implements Comparable<CLASSNAME>
2. compareTo 메서드 오버라이드
@Override
public int compareTo(Animal other) {
return Integer.compare(this.year_discovered, other.year_discovered);
}
ref : stackoverflow.com/questions/21626439/how-to-implement-the-java-comparable-interface
'Java' 카테고리의 다른 글
[Java] Arrays.sort 활용 (0) | 2022.10.14 |
---|---|
[Java] CollectionUtils.isEmpty의 장점 (0) | 2022.07.28 |
[Java] 엑셀 시트 이름 개선하기 (0) | 2022.06.08 |
[Java] 인터페이스 vs 추상클래스 (0) | 2022.04.04 |
[Java] JAR WAR 차이점 (0) | 2022.02.05 |