*
The moose likes Java in General and the fly likes search for a value within list of HashMaps Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "search for a value within list of HashMaps" Watch "search for a value within list of HashMaps" New topic
Author

search for a value within list of HashMaps

Mahesh Pinnamaneni
Ranch Hand

Joined: Jul 02, 2004
Posts: 100
Dear All,
can u pls give me the efficient way to solve this.
i am having an List in which array of HashMap's.
Ex: = List lst = new ArrayList();
HashMap hm = new HashMap(); //say we added some data to this
<k,v> - <"no","001"><"subno","01"> etc
All the hashmap data contains like this same structure.

here i want to get the HashMap in which the no=001 and subno=01 within the List.how can do this in an efficient way. one thing we can do is get the length of the List and iterate thru the loop.
better if we can have some other solution.
Thanks & regards,
Mahesh
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Mahesh Pinnamaneni:
...one thing we can do is get the length of the List and iterate thru the loop...

It seems that you're looking for a way to quickly find a particular HashMap within an ArrayList. Can you store the HashMaps within another HashMap instead of an ArrayList?

If that's not feasible, then you might consider building some sort of quick-lookup object (perhaps containing another HashMap as a "lookup table") with a method to return the desired HashMap's index in the ArrayList. But how "efficient" this might be depends on a lot of variables. In the end, you might be better off iterating through the ArrayList.

:roll:


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
 
 
subject: search for a value within list of HashMaps