I want to get all the values associated with a key in Map.
For e.g,
Map tempMap = new HashMap();
tempMap.put("1","X");
tempMap.put("2","Y");
tempMap.put("3","Z");
tempMap.put("1","ABC");
tempMap.put("2","RR");
tempMap.put("1","RT");
How to retrieve all the values associated with key 1 ?
|
I'm using the com.google.common.collect.ArrayListMultimap<K,V> collection to map Integers to Strings. The class provides a method called containsValue(Object value) which checks if the multimap contains the specified value for any key. Once ... |
I have a method-
private void mapSomething(Class<?> dataType){
if(dataType.isInstance(Map.class)){
// How do I get the key set of the map
}
}
Method is called ... |
Guys, this is silly, but i got to ask
You have a private Map<String, String> dbMap = new HashMap<String, String>();
i am putting stuff in after having read the ... |
Which data structure should i use to store and retrieve the following data?
(key1,val1)(key1,val2)(key1,val3)(key2,val4)(key2,val5)(key2,val6)(key3,val7)(key3,val8)(key3,val9)
Please help me.
|
I need to have a HashMap< Integer, String> which can serve fast operations for retrieving a list of all entries whose keys are in a certain integer range besides, getting values ... |
Dan, Keys need to unique. Wouldn't you be limited to one (or zero) null keys in a map? (Some maps don't allow null keys in which case this would be a moot point.) And you could get that one null key with map.get(null). I suspect I'm missing the point of the question here though. |
|
Hi , I have a HashMap with some values , And I want to retrieve that values . -------------- 1 --- Yes 2 --- No 3 --- Can't Say -------------- what I am doing is : itrMap = map.entrySet().iterator(); while(itrMap.hasNext()) { Map.Entry entry = (Entry)itrMap.next(); System.out.println(entry.getValue()); } But the problem with this is , I am getting values in reverse order ... |
Roger, I would never have thought of that. I'm going to look on the API right now! Thanks! (Of course I have looked, duh) Jesper, thanks for the suggestion, that solves the problem. I was trying to solve the problem by looking for something like a getKey() on an Iterator or something like that, this entrySet() is a different approach but ... |
|
|
|
mickey0 wrote: I just asked if there is a way to avoid the loop, yes, something like mymap.getAllKeySet() 1) Why? 2) If there were such a method, it would also have to loop. Have. To. There's no way around it. And the Java code that would do the loop in that method is no different than the looping Java code that ... |
|