aspose file tools*
The moose likes Java in General and the fly likes How to Add ArrayList<string> newlist to an ArrayList<Command> command Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to Add ArrayList<string> newlist to an ArrayList<Command> command" Watch "How to Add ArrayList<string> newlist to an ArrayList<Command> command" New topic
Author

How to Add ArrayList<string> newlist to an ArrayList<Command> command

nagraj patel
Greenhorn

Joined: Feb 16, 2013
Posts: 18
Hello Experts,


I have a problem .I want to add one ArrayList<string> type list to an ArrayList<Command> command . where Command is POJO Class .How I do That.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

You can't do that.

ArrayList<Command> means it holds only Command objects and their subclasses. That's the whole point of type parameterization, so that you can't stick some other object in that list.

Why would you want to mix Commands and Lists inside the same List anyway? That's a pretty bad design smell.

Does a Command object contain an ArrrayList<String> as a member variable? If so, you can create a Command and put your desired List into it, and add that Command to the List<Command>. Otherwise, you'll have to provide more details about what you're actually trying to accomplish.
Mack Wilmot
Ranch Hand

Joined: Jul 27, 2011
Posts: 88

Something like this maybe?

[MODERATOR ACTION: Removed full code solution]

Mack Wilmot, please remember that this site is NotACodeMill(←click). Full code solutions are discouraged. It is preferable to guide the OP toward finding his own solution. Thanks!
Mack Wilmot
Ranch Hand

Joined: Jul 27, 2011
Posts: 88

The NotACodeMill link is broken.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Mack Wilmot wrote:The NotACodeMill link is broken.


Weird. Yours works for me, but mine doesn't. I don't see a difference. Maybe I included a control character? Or maybe I'm just old and blind.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19693
    
  20

Your link includes "forums" in the path which shouldn't be there. That's odd though since the link is automatically generated.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
nagraj patel
Greenhorn

Joined: Feb 16, 2013
Posts: 18
I have requirement where I am reading text file from command line where each line of command have instance of Command class for every Command line have ArrayList<CommandMgrList> object ConmmandMgr is thread based object create a thread for every Command object How to do that..
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

nagraj patel wrote:I have requirement where I am reading text file from command line where each line of command have instance of Command class for every Command line have ArrayList<CommandMgrList> object ConmmandMgr is thread based object create a thread for every Command object How to do that..


Sorry, but I have no idea what you're trying to say here.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to Add ArrayList<string> newlist to an ArrayList<Command> command