I have a java map with string in its key and integer in its value. I want to remove a particular entry(key/value) from this map which doesn’t have value greater than 5. Can any body suggest me how can I do this?
Thanks!
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.
If you’ve only got a regular map (i.e. no additional data structure that implements a reverse mapping), then your best option is to iterate the value set, test each value, and use
Iterator.remove()to remove the relevant ones.If you have a secondary data structure, you may be able to use it to identify the entries to be removed. But the “cost” is that such a data structure takes space to represent and time to update … and your code is more complex.