How to Replace the value in particular key in LinkedHashMap How to Replace the value in particular key in LinkedHashMap android android

How to Replace the value in particular key in LinkedHashMap


You put a new value for that key :

map.put("key2","value8");map.put("key4","value6");

Note that for LinkedHashMap, changing the value for an existing key won't change the iteration order of the Map (which is the order in which the keys were first inserted to the Map).


In Map(LinkedHashMap) key is the unique value. So whenever you try to put a value for a key, it will either add new entry in map or if key already exist then it will replace old value for that key with new value.

map.put("existing key", "new value");

Above code will replace value of existing key in map with new value.


The proper way of checking if the key is present or not:

  if (map.containsKey(key)) {      map.put("existing key", "newValue");  }