File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Convert from HashMap to ArrayList

 
Kasey Austin
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I want to convert from a HashMap, Key Value pair 1 to 1, to a HashMap where the Keys are Strings and the Values are arraylist. This way, I can have 1 key mapped to many values.

This is the code:


When I try this I am getting this error:
The method put(String, ArrayList<String>) in the type Map<String,ArrayList<String>> is not applicable for the arguments (String, void)

Can you provide an example?
Thanks for your help.
Kasey
 
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
You're trying to put the return value of "add()" into the Map, which doesn't work since add() returns void. Instead, you just have to do this as two lines:

 
John de Michele
Rancher
Posts: 600
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kasey:

Another way to do it would be like this:

John.
 
Kasey Austin
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ernest, Thanks John
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kasey Austin wrote:Thanks Ernest, Thanks John


and welcome to javaranch
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic