【Java开源代码栏目提醒】:网学会员,鉴于大家对Java开源代码十分关注,论文会员在此为大家搜集整理了“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());
}
}