aspose file tools*
The moose likes Struts and the fly likes Iterating over HaspMap<String,List<Object>> and comparing values. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Iterating over HaspMap<String,List<Object>> and comparing values." Watch "Iterating over HaspMap<String,List<Object>> and comparing values." New topic
Author

Iterating over HaspMap<String,List<Object>> and comparing values.

Khan Tanoli
Greenhorn

Joined: Feb 16, 2011
Posts: 6

Hi:

Thanks for taking time to read my post. I've looked around but am having a tough time finding an answer.

I have a HashMap<String,List<Object>> that i am trying to iterate through: this part i know how to do i.e. iterating through a hasmap with a string as key and a list of object as value. However, the question is: as i'm iterating, the value which is a List<Object> for each key of type String in the Map, has additional properties. Let say each object in the list has 3 properties: id, createdate, expiredate. The key for each entry is the same as the id attribute for each Object in the list. I have another map that has data in it and i'm trying to print values from that map and this map only when the id attribute of the Object in the list matches the id attribute from the other map.

Is this possible? would it be something like <s:if test="value.id == othermapValue.id">some logic</s:if><s:else>some logic</s:else>

over here the value.id is the id attribute of the Object in the list that is at the current iteration. I don't know how to access that attribute ... i mean do i reference it using index as thismapvalue[0] == othermapvalue[0] or is there some other way?

If my question is not clear enough, please let me know.

Thanks.
EDIT: appears that MOD moved my message to the struts forum. I'm using the struts tag library as an example, but this is still all happening inside a jsp page, so i'm open to using other tag libraries thanks.
Khan Tanoli
Greenhorn

Joined: Feb 16, 2011
Posts: 6

After searching around i finally discovered the solution myself. Maybe no one responded as my question was vague. So the answer to the problem is as follow:

if you have a map that is setup as Map<List<Object>,object> tempMap = new HashMap<List<Object>,Object>();

then to iterate through this map in jsp and use data from this map to compare to other fields in jsp you have to do something like:


Hope this helps anyone else out there looking for a solution like this.

Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Iterating over HaspMap<String,List<Object>> and comparing values.