9:59 pm - Monday October 15, 2018

HashMap Example program for 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
/**
Author :candidjava.com
Description: It removes a value of specific key from HashMap.
*/
import java.util.*;
public class HashMapRemove
 {
public static void main(String arg[])
{
HashMap<Integer, String> osHashMap = new HashMap<Integer, String>(); // Create object  of hashmap
osHashMap.put(new Integer(1), "ABC");
osHashMap.put(new Integer(2), "DEF");
osHashMap.put(new Integer(3), "GHI");
System.out.println("HashMap before remove : " + osHashMap);
osHashMap.remove(2);
System.out.println("HashMap after remove : "+osHashMap);
}
 }

Output:
HashMap before remove : {1=ABC, 2=DEF, 3=GHI}

HashMap after remove : {1=ABC, 3=GHI}

BACK

Filed in: Z-A All Java Codes

Comments are closed.