3:13 pm - Thursday December 16, 8804

clear all elements from treemap void Clear()

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 clear all elements from treemap using Clear() method.we can’t clear the particular data ,it will clear all the data.

Example


import java.util.TreeMap;

public class TreeMapClear

{

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("Value of second: "+hm.get("second"));

   System.out.println("Is TreeMap empty? "+hm.isEmpty());

   hm.clear();

   System.out.println(hm);

 }

}

Output

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

Value of second: SECOND INSERTED

Is TreeMap empty? false

            {}

BACK

 

Filed in: Java Examples, Z-A All Java Codes

Comments are closed.