We can remove the values of HashMap in Java by using clear() method as follows:
import java.util.HashMap;
HashMap<Integer,String> map = new HashMap<>();
map.put(1,”Hello”);// add key-value pair
map.put(2,”Hi”);
System.out.println(“Before clear: ” + map); // {1=Hello, 2=Hi}
map.clear(); // remove all entries
System.out.println(“After clear: ” + map); // {}
sukanya meruva Answered question