9:40 pm - Saturday January 21, 2017

Remove a data from treemap by its key V remove(Object key)

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 Remove a data from treemap by its key using V remove(Object key) method.Previous value associated with key, or null if there was no mapping for key.

 

Example :

 

import java.util.TreeMap;

public class TreeMapCheckEmpty

{

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.remove(“third”);

System.out.println(hm);

}

}

 

Output :

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

Value of second: SECOND INSERTED

Is TreeMap empty? false

{first=FIRST INSERTED, second=SECOND INSERTED}

BACK

Filed in: Java Training

Comments are closed.