import java.util.*;결과:
public class SortedMap {
public static void main(String[] args) {
// 제네릭 유형으로 트리맵을 만듭니다
TreeMaptm = new TreeMap ();
// 트리맵 채우기
tm.put(1, "one");
tm.put(2, "둘");
tm.put(3, "셋");
tm.put(4, "넷");
tm.put(5, "다섯");
// 모든 키 검색
Set set = tm.entrySet();
// iterator
iterator it = set.iterator();
// 트리맵을 탐색하여 요소 표시
while(it.hasNext()) {
Map.Entry mapentry = (Map.Entry)it.next();
System.out.print("["+mapentry.getKey() +", ");
System.out.println(mapentry.getValue()+"]");
}
}
}
[1, 하나]
[2, 둘]
[3, 3]
[4, 4]
[5, 5]
Please disable your ad blocker and refresh the window to use this website.