| Author |
List to Map conversion
|
Nicolas Flammel
Ranch Hand
Joined: May 05, 2004
Posts: 32
|
|
How can I convert a list to a map object? [ May 26, 2004: Message edited by: Nicolas Flammel ]
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
|
There is no addAll(Collection) method for Map, (there is one defined in the Collection interface, but it is unsupported by the Map class) so I think you will have to iterate through the List and add each entry to the Map yourself.
|
JavaRanch FAQ HowToAskQuestionsOnJavaRanch
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24061
|
|
|
Yes, Paul is right. Note that there's certainly no obvious way that such an addAll() could be implemented: what would it use for the keys?
|
[Jess in Action][AskingGoodQuestions]
|
 |
Dirk Schreckmann
Sheriff
Joined: Dec 10, 2001
Posts: 7023
|
|
|
Moving this to the Intermediate forum...
|
[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
|
 |
Chengwei Lee
Ranch Hand
Joined: Apr 02, 2004
Posts: 884
|
|
If my memory serves me well, I remember this topic has been discussed somewhere here or in Java Developers Forum... Anyway, a map stores a key-value pair, but a list don't. So if you're to convert your list into a map, how would you want to access your contents? In short, what is the key that identifies your value in the map going to be?
|
SCJP 1.4 * SCWCD 1.4 * SCBCD 1.3 * SCJA 1.0 * TOGAF 8
|
 |
 |
|
|
subject: List to Map conversion
|
|
|