suppose you have a HashMap m
and there is already a key value pair <"key1", object> inside.
can you do the following?
m.put("newkey", m.remove("key1"))
will you get a ConcurrentModificationException?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can do that as long as it’s not in the body of a loop that is iterating over the hashMap entries. The way that will work is that the remove operation will execute and complete before the put operation so it’s semantically equivalent to doing it in 2 lines.