Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
nagraj patel
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 88
Linux Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 88
Linux Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The NotACodeMill link is broken.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your link includes "forums" in the path which shouldn't be there. That's odd though since the link is automatically generated.
 
nagraj patel
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic