Get Size of TreeMap - Java Collection Framework

Java examples for Collection Framework:TreeMap

Description

Get Size of TreeMap

Demo Code

 
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());
  }
}

Result


Related Tutorials