3:13 pm - Monday December 16, 9320

Get size of Treemap using int size()

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

BACK 

                      This tutorial explains how  to Get size of Treemap using  int size() method.Count the number of elements in the tree map using size() function.

Example

import java.util.TreeMap;
public class TreeMapSize

{

public static void main(String a[])

{

   TreeMap<String, String> hm = new TreeMap<String, String>();

   hm.put("first", "FIRST INSERTED");

   hm.put("second", "SECOND INSERTED");

   hm.put("third","THIRD INSERTED");

   System.out.println(hm);

   System.out.println("Size of the TreeMap: "+hm.size());
 }
}

Output 

               {first=FIRST INSERTED, second=SECOND INSERTED, third=THIRD INSERTED}

               Size of the TreeMap: 3

BACK

Filed in: Java Examples

Comments are closed.