Sunday 13 April 2014

size : Number Of Key-value Mappings

int size()
Returns the number of key-value mappings in this map. If the map contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

import java.util.*;
class MapSize{
  public static void main(String args[]){
    Map<Integer, String> studentTable = new TreeMap<> ();
  
  /* Add Student details */
  studentTable.put(123, "Krishna");
  studentTable.put(124, "Ram");
  studentTable.put(125, "Anil");
  studentTable.put(126, "Kiran");
  
  System.out.println("Data in Student Map is");
  System.out.println(studentTable);
  
  System.out.print("Number Of Key-value Pairs are ");
  System.out.println(studentTable.size());
  }
}

Output
Data in Student Map is
{123=Krishna, 124=Ram, 125=Anil, 126=Kiran}
Number Of Key-value Pairs are 4

Prevoius                                                 Next                                                 Home

No comments:

Post a Comment