Sunday, 8 June 2014

TreeMap : size() : get the number of Maps

public int size()
Returns the number of key-value mappings in this map.

import java.util.*;

class TreeMapSize{
 public static void main(String args[]){
  TreeMap<Integer, String> myMap;
  
  myMap = new TreeMap<> ();
  
  /* Add Elements to myMap */
  myMap.put(2, "w");
  myMap.put(4, "wx");
  myMap.put(6, "wxy");
  myMap.put(8, "wxyz");
  
  System.out.println("Elements in myMap are");
  System.out.println(myMap);
  
  System.out.print("Number Of Mappings are ");
  System.out.println(myMap.size());
 }
}

Output
Elements in myMap are
{2=w, 4=wx, 6=wxy, 8=wxyz}
Number Of Mappings are 4



Prevoius                                                 Next                                                 Home

No comments:

Post a Comment