자바 SortedMap

개요[ | ]

,map에는 순서가 없으나 sortedmap은 순서가 있음
sortedmap은 인터페이스며, 해당 인터페이스를 모두 구현한 클래스로 TreeMap이 있음
  • SortedMap을 구현한 TreeMap 예제
import java.util.SortedMap;
import java.util.TreeMap;
class Main {
    public static void main(String[] args) {
        SortedMap<String, Integer> numbers = new TreeMap<>();
        numbers.put("Two", 2);
        numbers.put("One", 1);
        System.out.println("SortedMap: " + numbers);
        System.out.println("First Key: " + numbers.firstKey());
        System.out.println("Last Key: " + numbers.lastKey());
        int value = numbers.remove("One");
        System.out.println("Removed Value: " + value);
    }
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}