java program to remove , replace (key,value) from HashMap.
import java.util.;
import java.io.;
class HashMapRemoveReplace
{
public static void main(String[] args)
{
HashMap<Integer,String> hm=new HashMap<Integer,String>();
hm.put(1,"Brijesh");
hm.put(2,"Badal");
hm.put(3,"Abhishek");
hm.put(4,"Sarvesh");
System.out.println(hm);
System.out.println();
for(Map.Entry m:hm.entrySet())
{
System.out.println(m.getKey()+" "+m.getValue());
}
//key based removel
hm.remove(4);
System.out.println(hm);
//key-value pair based removel
hm.remove(3,"Abhishek");
System.out.println(hm);
//replacing value to related key
hm.replace(1,"Brijesh","Kumar");
System.out.println(hm);
//replacing all value with given key-value
hm.replaceAll((k,v)->"Brijesh");
System.out.println(hm);
}
}