0

How do i get the key of "tradeid3" ? Is there any inbuilt method that does it?

import java.util.Map;
import java.util.HashMap;
import java.util.Iterator;


public class abcd{
    public static void main(String args[]){
    Map m= new HashMap(); 
        m.put("TRADEID1", "tradeid1");
        m.put("TRADEID2", "tradeid2");
        m.put("TRADEID3", "tradeid3");
    }
}
3
Contributors
3
Replies
16
Views
4 Years
Discussion Span
Last Post by stultuske
0

You haven't given any background about data size, data volatility, key-value duplicates etc, but if it's low volatility with only one value for each unique key, I would consider two Maps, the second one having the keys and values swapped so you can retrieve the key directly from the value.
I assume you have already looked at whether you should be using a HashMap or a TreeMap? (eg do you want to print the data sorted in some order?)

0

either that, or let the value be an Object which has two elements: the actual value and the key. but that just sounds weird :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.