how to access a hashmap which is inside a MultiMap
I am having a Multimap which contains key as sitename and Values is another hashmap.
I am getting these values from Database.
Code :
LinkedHashMap> thisHash = new <LinkedHashMap();
thisHash.put(fiscal_date,avg_RT);
siteMap.put(site_name,thisHash);
The sample value in my hashmap is
Key: New York, Value: {06/13/2012=1.3}. Value: {06/14/2012=1.48}.
Key: Bangalore, Value: {06/13/2012=2.53}. Value: {06/14/2012=3.08}.
Key: San Jose, Value: {06/13/2012=1.25}. Value: {06/14/2012=1.28}.
Key: Amsterdam, Value: {06/13/2012=1.71}. Value: {06/14/2012=2.27}.
Now I need to access the LinkedHashMap which is inside this multimap and get the key and value seperately. Please help me to do the same.
Re: how to access a hashmap which is inside a MultiMap
What is a multimap? Is that a class you have defined?
Re: how to access a hashmap which is inside a MultiMap
Quote:
Now I need to access the LinkedHashMap which is inside this multimap and get the key and value seperately.
Reverse the steps you use to put the data into the collection. That is, take the collection and get the map associated with the site name. Then take this latter map and get whatever data you want from it. (eg the value for a given date, or the complete set of date/value pairs etc).
-----
If you get stuck, post code which at least compiles. Multimaps are not a standard Java collection, so identify what package you are getting this from (Google, Apache etc...).
Re: how to access a hashmap which is inside a MultiMap
MultiMap is a Apache Package.
I am importing import org.apache.commons.collections.MultiMap.*;
I have tried to get the Value of Collection into a HashMap. But as it is only 1 parameter, I am getting error.
Quote:
Set keySet = siteMap.keySet();
Iterator keyIterator = keySet.iterator( );
while( keyIterator.hasNext( ) ) {
Object key = keyIterator.next( );
System.out.print( "Key: " + key + ", " );
Collection values = (Collection) siteMap.get( key );
Iterator valuesIterator = values.iterator( );
while( valuesIterator.hasNext( ) ) {
LinkedHashMap Hash1 = new LinkedHashMap();
Hash1 = valuesIterator.next();
System.out.print( "Value: " + valuesIterator.next( ) + ". " );
System.out.print("List value" + Hash1);
}
System.out.print( "\n" );
}
Here data types for Hash1 is LinkedHashMap and valuesIterator.next() is returning java.lang.object.
Please help.
Re: how to access a hashmap which is inside a MultiMap
Quote:
I am getting error.
Please post the full text of the error message and show the code causing it.