| Author |
more than one add in a list/set ?
|
nimo frey
Ranch Hand
Joined: Jun 28, 2008
Posts: 580
|
|
Is there a shortcut for that:
can I do something like?:
|
 |
Harshit Rastogi
Ranch Hand
Joined: Apr 15, 2008
Posts: 131
|
|
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
|
<a href="http://technologiquepanorama.wordpress.com" target="_blank" rel="nofollow">My Techie Blog</a><br /><a href="http://www.java-questions.com" target="_blank" rel="nofollow">Java Questions</a>
|
 |
Maneesh Godbole
Saloon Keeper
Joined: Jul 26, 2007
Posts: 8441
|
|
|
Check out the addAll() method.
|
[Donate a pint, save a life!] [How to ask questions] [Onff-turn it on!]
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
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?
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
nimo frey
Ranch Hand
Joined: Jun 28, 2008
Posts: 580
|
|
|
okay thanks!
|
 |
 |
|
|
subject: more than one add in a list/set ?
|
|
|