Hi just wanting to see how you can iterate over a hashmaps entry set checking both the key and values, if either matches the string passed it will return the other (if it matches the key it will return the value, if it matches the value it will return the key)?

Thanks

Recommended Answers

This makes very little sense: what if there is a value that appears as both key and value? how will you know which to return then?

Jump to Post

All 3 Replies

This makes very little sense: what if there is a value that appears as both key and value? how will you know which to return then?

There isn't, I have a set of the key/value pairs and they are all unique. I just wasn't sure if there was a way to do it this way..it's the way I have been instructed to do this task.

OK, yes you can iterate through the entrySet() (hint!). For each entry you can getKey() and getValue()and test them to see if either is the one you want

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.