import java.util.*;结果:
public class SortedMap {
public static void main(String[] args) {
// 创建一个具有泛型类型的 TreeMap
TreeMaptm = new TreeMap ();
// 填充树图
tm.put(1, 一”);
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, one]
[2, two]
[3, three]
[4, four]
[5, five]
Please disable your ad blocker and refresh the window to use this website.