import java.util.Collections;结果:
import java.util.Iterator;
导入 java.util.Set;
导入 java.util.TreeMap;
import java.util.Map;
public class reverseOrder {
public static void main(String a[]){
// 创建 TreeMap
TreeMap<字符串、整数>tmap =
新的树状图<字符串、整数>(Collections.reverseOrder());
// 在 TreeMap
tmap.put(Key1”,1);
tmap.put(键2”,2);
tmap.put(键3”,3);
tmap.put(键4”,4);
// 获取所有输入
Set set = tmap.entrySet();
// 获取迭代器浏览列表
迭代器 itr = set.iterator();
// 显示键值对
while(itr.hasNext()) {
Map.Entry mentry = (Map.Entry)itr.next();
System.out.print(键: ”+mentry.getKey() + - ”);
System.out.println(值:”+mentry.getValue());
}
}
}
key: key4 - value: 4
key: key3 - value: 3
key: key2 - value: 2
key: key1 - value: 1
Please disable your ad blocker and refresh the window to use this website.