I am calling function that returns TreeMap
instance, and in the calling code I wanted to modify the TreeMap
. However, I am getting a ConcurrentModificationException
.
Here is my code:
public Map<String, String> function1() {
Map<String, String> key_values = Collections.synchronizedMap(new TreeMap<String, String>());
// all key_values.put() goes here
return key_values;
}
And my calling code is:
Map<String, String> key_values =Collections.synchronizedMap(Classname.function1());
//here key_values.put() giving ConcurrentModificationException