treemapdemo.java

来自「JAVA编程思想源代码 值得一下 很难找的」· Java 代码 · 共 35 行

JAVA
35
字号
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 + =
减小字号Ctrl + -
显示快捷键?