Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

more than one add in a list/set ?

 
nimo frey
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Is there a shortcut for that:



can I do something like?:

 
Harshit Rastogi
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


this is not possible.
other possible way could be ,put all your objects in an array and loop through it and
add it to the list
 
Maneesh Godbole
Saloon Keeper
Posts: 11027
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the addAll() method.
 
Rob Spoor
Sheriff
Pie
Posts: 20533
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But addAll requires that the objects are in another collection. Although using varargs, you could use the following:

I wouldn't do that however; although you save a few lines, it does create an extra array (for the varargs), and then another List object. In the end the result is the same. So you have to ask yourself this: is being lazy / shrinking your source code enough reason to warrant slower code (create the array and object takes time as well) that uses more memory?
 
nimo frey
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
okay thanks!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic