Get Size of Java TreeMap : TreeMap « Collections Data Structure « Java






Get Size of Java TreeMap

 

import java.util.TreeMap;

public class Main {
  public static void main(String[] args) {
    TreeMap<String, String> treeMap = new TreeMap<String, String>();
    System.out.println("Size of TreeMap : " + treeMap.size());

    treeMap.put("1", "One");
    treeMap.put("2", "Two");
    treeMap.put("3", "Three");

    System.out.println("Size of TreeMap after addition : " + treeMap.size());
    treeMap.remove("2");
    System.out.println("Size of TreeMap after removal : " + treeMap.size());

  }

}

   
  








Related examples in the same category

1.TreeMap
2.Read file content and save to a TreeMap
3.Get Synchronized Map from Java TreeMap
4.Check if a particular key exists in Java TreeMap
5.Get Set view of Keys from Java TreeMap
6.Get Tail Map from Java TreeMap
7.Remove value from Java TreeMap
8.Iterate through the values of Java TreeMap
9.Check if a particular value exists in Java TreeMap
10.Remove all values from Java TreeMap
11.Get Sub Map from Java TreeMap
12.Get lowest and highest key stored in Java TreeMap
13.Get Head Map from Java TreeMap
14.Use Generic TreeMap to store Integer as key and String as value