We would like to know how to replace key and value in hashmap with identical key and different values.
import java.util.HashMap; import java.util.Map; //w ww .j av a2 s . c o m public class Main { public static void main(String args[]) { Map<Integer, String> mils = new HashMap<>(); mils.put(1, "foo"); mils.put(2, "bar"); System.out.println("mils:\t" + mils); mils.put(1, "bar"); System.out.println("mils:\t" + mils); } }
The code above generates the following result.