File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Convert List to a Map Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Convert List to a Map" Watch "Convert List to a Map" New topic

Convert List to a Map

vidu mayur
Ranch Hand

Joined: Nov 13, 2003
Posts: 32
There is a LinkedList with elements which have a key and a value. For example.,
List ls contains
I want this to be mapped as
HashMap hm = {1=one, 2=two, 3=three}
How do I do that?
Thanks in advance
chi Lin
Ranch Hand

Joined: Aug 24, 2001
Posts: 348
Use StringTokenizer to parse the elements of the
LinkedList, use "=" as delimiter.
for each element,
first token : key
2nd token : value
put the (key, value) into the map

not so smart guy still curious to learn new stuff every now and then
vidu mayur
Ranch Hand

Joined: Nov 13, 2003
Posts: 32
Thanks a lot! That worked perfectly!
I agree. Here's the link:
subject: Convert List to a Map
It's not a secret anymore!