• Post Reply Bookmark Topic Watch Topic
  • New Topic

Convert Collection To A HashMap

 
Vivek Mathur
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I Have a collection that have data in form of only two columns, like key/sno and Text/Description.(I got this Collection using EJB's finder Method - at my some Java Class that act as a bean -> this is used at JSP(to fill the select box) ).

Now I want to convert it to a HashMap(key,data).Previously i was doing it by making an iterator and then using while loop fetch both code and description(using getter method's of EJB) set that in HashMap.

I have many Collections(number is dynamic -can be more than 100).
so by using Iterator it hits the performance. As all this is done inside nested loops.

Can any one please let me know the easiest way to convert Collection to HashMap.Is there any method that can do so ?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35743
412
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vivek,
Any method would still need to loop through the collection.

Do you have an actual performance problem here or is this speculation? And if you do have a performance problem, is it being caused by the database query/hits or the looping. I would be shocked if the looping was doing it.

If the problem is the database query/hits, describe some more and you can get tips on optimizing that part.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!