Home Tutorial Java Core HashMap Java hashmap clear() method example.

 
 

Share on Google+Share on Google+
Java hashmap clear() method example.
Posted on: April 6, 2011 at 12:00 AM
Advertisement
Java hashmap clear() method example.

Java hashmap clear() method example.

This tutorial is based on clear() method of java HashMap class. It removes all values from HashMap.

Code

HashMapRemoveAll.java

package net.roseindia.java;

import java.util.HashMap;

public class HashMapRemoveAll{

public static void main(String[] arr) {

/* Create a object of HfasHMap */

HashMap<Integer, String> obMap = new HashMap<Integer, String>();

/* Add values into HashMap */

obMap.put(new Integer(1), "AAAA");

obMap.put(new Integer(2), "BBBB");

obMap.put(new Integer(3), "CCCC");

obMap.put(new Integer(4), "DDDD");

obMap.put(new Integer(5), "EE");

/*Display Element before clear method */

System.out.println("HashMap : " + obMap);

/*Remove all values from HashMap*/

obMap.clear();

/*Display Element after clear method */

System.out.println("HashMap : "+obMap);m } }

Output :

HashMap : {1=AAAA, 2=BBBB, 3=CCCC, 4=DDDD, 5=EE}

HashMap : {}

Advertisement

Related Tags for Java hashmap clear() method example.:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 6, 2011

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com