wood burning stoves 2.0*
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 Android Security Essentials Live Lessons 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
Author

Convert List to a Map

vidu mayur
Ranch Hand

Joined: Nov 13, 2003
Posts: 32
Hi
There is a LinkedList with elements which have a key and a value. For example.,
List ls contains
1=one
2=two
3=three
I want this to be mapped as
HashMap hm = {1=one, 2=two, 3=three}
How do I do that?
Thanks in advance
Vidu
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: http://aspose.com/file-tools
 
subject: Convert List to a Map
 
Similar Threads
ordering of elements in Hashtable
Set difference method
Storing Array of String in MS-Access
another question from scjptest.com
DLL's