share

Wednesday, 17 June 2015

How to delete all elements from HashMap

import java.util.HashMap;import java.util.Map;

public class HashMapDeleteAll {

public static void main(String[] args) {

Map<Integer,String> hm = new HashMap<Integer,String>();

/* * Associates the specified value with the specified key in this map (optional operation). If the map previously contained a mapping for the key, the old value is replaced by the specified value */ hm.put(1,"ankush"); hm.put(2, "amit"); hm.put(3,"shivam"); hm.put(4,"ankit"); hm.put(5, "yogesh");