I have MultivalueMap and a TreeMap, both have key-value of type String.
I wish to change any key in my MultivalueMap to keys found in my TreeMap.
This is my code, why do I get ConcurrentModificationException and how to solve it?
public RestRequest(MultivaluedMap<String, Object> myHeaders,TreeMap<String, String> testParameters) {
this.testParameters = testParameters;
buildUrl();
Client client = ClientBuilder.newClient();
Set<String> keys = myHeaders.keySet();
for (String key : keys) {
myHeaders.remove(key);
myHeaders.add(key, testParameters.get(key));
}
this.myHeaders = myHeaders;
myResource = client.target(URL);
entity=Entity.entity(replaceRequestBodyWithParams(requestBody), MediaType.APPLICATION_JSON);
}