• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

List to Map conversion

 
Nicolas Flammel
Ranch Hand
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I convert a list to a map object?
[ May 26, 2004: Message edited by: Nicolas Flammel ]
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to the Intermediate forum...
 
Chengwei Lee
Ranch Hand
Posts: 884
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic