• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

search for a value within list of HashMaps

 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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:
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!