Java examples for Collection Framework:TreeMap
Get Size of TreeMap
import java.util.TreeMap; public class Main { public static void main(String[] args) { // w ww .ja va 2s. co m TreeMap treeMap = new TreeMap(); System.out.println("Size of TreeMap : " + treeMap.size()); //add key value pairs to TreeMap using put method treeMap.put("1","One"); treeMap.put("2","Two"); treeMap.put("3","Three"); System.out.println("Size of TreeMap after addition : " + treeMap.size()); //remove one element from TreeMap using remove method Object obj = treeMap.remove("2"); System.out.println("Size of TreeMap after removal : " + treeMap.size()); } }