File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Convert from HashMap to ArrayList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Convert from HashMap to ArrayList" Watch "Convert from HashMap to ArrayList" New topic
Author

Convert from HashMap to ArrayList

Kasey Austin
Greenhorn

Joined: May 04, 2009
Posts: 2
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

Joined: Jul 08, 2003
Posts: 24183
    
  34

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:



[Jess in Action][AskingGoodQuestions]
John de Michele
Rancher

Joined: Mar 09, 2009
Posts: 600
Kasey:

Another way to do it would be like this:

John.
Kasey Austin
Greenhorn

Joined: May 04, 2009
Posts: 2
Thanks Ernest, Thanks John
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Kasey Austin wrote:Thanks Ernest, Thanks John


and welcome to javaranch
 
 
subject: Convert from HashMap to ArrayList