📄 treemapdemo.java
字号:
package chapter9;
import java.util.Comparator;
import java.util.Iterator;
import java.util.TreeMap;
public class TreeMapDemo {
public static void main(String[] args) {
TreeMap<String, String> tm = new TreeMap<String, String>();
tm.put("1", "aa");
tm.put("2", "bb");
tm.put("3", "cc");
tm.put("9", "dd");
tm.put("88", "ee");
tm.put("6", "ff");
System.out.println("the tree map is " + tm);
Comparator com = tm.comparator();
TreeMap<String, String> tm2 = new TreeMap<String, String>(com);
tm2 = (TreeMap<String, String>) tm.clone();
// firstkey method
System.out.println("the first key in tm2 is :" + tm2.firstKey());
// keySet method
Iterator iter = tm.keySet().iterator();
for (; iter.hasNext();) {
System.out.println("the value is " + tm.get(iter.next()));
}
// clear method
tm2.clear();
System.out.println("the size of tm2 is :" + tm2.size());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -