11.7.1 Comparator와 Comparable
- Array.sort()는 Character클래스의 Comparable의 구현에 의해 정렬되는 것임
- Comparator와 Comparable은 모두 인터페이스로 컬렉션을 정렬하는데 필요한 메소드를 정의하고 있음
public interface Comparator{ int compare(Object o1, Object o2); boolean equals(Object obj); } public interface Comparable{ public int compareTo(Object o); }
- Comparable은 기본 정렬 기준을 구현하는데 사용함
- Comparator는 기본 정렬기준 외에 다른 기준으로 정렬하고자 할 때 사용함
'자바의 정석 정리' 카테고리의 다른 글
자바의 정석 - 11.9 TreeSet (0) | 2022.09.05 |
---|---|
자바의 정석 - 11.8 HashSet (0) | 2022.09.05 |
자바의 정석 - 11.6 Arrays (0) | 2022.09.05 |
자바의 정석 - 11.5 Iterator, ListIterator, Enumeration (0) | 2022.09.05 |
자바의 정석 - 11.4 LinkedList (0) | 2022.09.05 |