Map<String,String> map=request.getParameterMap();
^ is the unmodifiable map.
Set s1= map.keySet();
Set s2= map2.keySet();/* another keyset of local map*/
Using s1.retainAll(s2) throws an exception: at java.util.collections$unmodifiablecollection.retainall
Here request.getParameterMap() returns an unmodifiable map.. I tried creating a local map. But the issue stil persists.
Suggest some solution.
The Set.retainAll method modifies the set it's being called on. Assuming the keySet method of you unmodifiable map is just a view on to the underlying map, it shouldn't allow modifications. You probably want to create a new (modifiable) set and then remove items from it:
Set s1 = new HashSet(map.keySet());
s1.retainAll(s3);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With