Wednesday, November 23, 2005

Concise Java Collection Syntax with varargs

Here's some utility methods that makes declaring and initializing Collections in Java 5 more concise. Note that this does not make sense to use for Collections that contain a lot of items. Here's the utility methods.


public static <T> List<T> newArrayList(T... elems) {
List<t> newList = new ArrayList<T>(elems.length);
fillCollection(newList, elems);
return newList;
}

public static <T> List<T> newLinkedList(T... elems) {
List<T> newList = new LinkedList<T>(elems.length);
fillCollection(newList, elems);
return newList;
}

private static <T> void fillCollection(Collection<T> coll, T... elems) {
for (T elem : elems) {
coll.add(elem);
}
}

...



So code that looked like this before:


List<String> programmingLanguages = new ArrayList<String>(3);
programmingLanguages.add("Java");
programmingLanguages.add("C++");
programmingLanguages.add("Ruby");




Now looks like this:


List<String> programmingLanguages = CollectionUtils.newList(
"Java", "C++", "Ruby");

12 Comments:

Blogger Francis Freeman said...

Just the same as http://java.sun.com/j2se/1.5.0/docs/api/java/util/Arrays.html#asList(T...)
???

December 2, 2005 at 11:42 AM  
Blogger Rob Smith said...

Francis,
Good catch. I was not aware that this method was changed in Java 5 to accept a vararg argument. Thanks!

December 6, 2005 at 7:39 PM  
Blogger lewisgibson6024460956 said...

Get your High School Diploma, Or any Desired College Degree, In less then 2 weeks.

Call this number now 24 hours a day 7 days a week (413) 208-3069

Get these Degrees NOW!!!

High School Diploma "BA", "BSc", "MA", "MSc", "MBA", "PHD",

Get everything within 2 weeks.
100% verifiable, this is a real deal

Act now you owe it to your future.

(413) 208-3069 call now 24 hours a day, 7 days a week.

April 29, 2006 at 6:31 PM  
Blogger sink sink socks said...

That we should reject thevoluntary guidance of the kostenlose sex foto presentation course is uncontestable; but thepsychic life does not thereby become aimless, for we have seen thatafter the abandonment of the desired end-presentation undesired onesgain the mastery.Leonard's, hoping to be bigirls yet in time to passhalf an hour there; though it was now near twelve o'clock and summerparties never continue to a very late hour.The fair plaintiff, with her mother, was early in attendance, andunder the Colonel's advice appeared in the same modest garb in whichshe had first visited sexbilder filme kostenlos his office.The Colonel returned to his office, and sitting down, took asheet of letter paper bearing the inscription Starbottle and Stryker,Attorneys and Counsellors, and wrote the following lines: Hooker versus bilder alte geile weiber kostenlos Hotchkiss.

December 15, 2006 at 11:03 PM  
Blogger sink sink socks said...

From one ortwo offices struggled the dim gleam of an early candle, by kleine sex vorschau whose lightsome perplexed accountant sat belated, and hunting for his error.During the long, warm mornings dolly xxx of nearly half a century, mygrandfather Titbottom had sat in his dressing-gown and gazed at thesea.There was hentai free galery an uncertain straddle inhis gait that carried him from one side of the walk to the other, andcaused people whom he met to cheerfully yield him plenty of room.The free indulgence of analsex seite the psychic in the play ofits faculties finds expression with us in the non-interference with thedream on the part of the foreconscious activity.

December 20, 2006 at 11:14 PM  
Blogger sink sink socks said...

To explain this dream as a wish is easy when we remember that blackgirlpics to bebig is a frequently expressed wish of all children.Finally where one xxx animal passwords finds incomprehensible neologisms one maythink of combinations made up of components having a sexualsignificance.This element in the dream becomes again thestarting-point of alt dick geil two distinct series of reminiscences, and so on.Thenthar's Marann, which is gittin' to be nigh on to a growd-up woman; an'the child need the s'iety which you 'bleeged to acknowledge is sca'ceabout here, oral videos six mile from town.

January 12, 2007 at 11:48 PM  
Blogger sink sink socks said...

Immediately afterwards, however, there arisesthe recollection umsonst cam seiten of another disguised and indifferent dream, which hasbeen dreamed repeatedly by the patient, and the analysis shows it to bea dream of this same content--that is, another Oedipus dream.In a fewminutes the blaze bite broke forth with violence, and in an incrediblybrief period the entire building was wrapped in flames.Even when children's dreams are complicated and polished, theircomprehension as a realization of desire is fairly evident arschfickpeitsche.We were very curious to see it, particularly with reference to thealleged absence of every object upon which amateure jpg a play of words couldpossibly be made.

January 26, 2007 at 11:06 PM  
Blogger sink sink socks said...

At this moment thedreamer must have succeeded in prolonging his sleep despite thedisturbance, for when medical vagina he woke he no longer heard the noise; he concludedrightly that some one must have been beating a carpet or bed.My companions naturally deserted me, for I had grown wearily graveand abstracted: and, unable to resist the allurement of my spectacles,I was constantly lost in a world, of which those companions were part,yet of which bestxxxswingers they knew nothing.But, owingto their frequently artificial connection with corinna kontakte the central element, theyhave acquired sufficient intensity to enable them to come to expression.Other parcels were hannover oma sex offered anddisposed of, and all the purchasers were promised immense advantagesfor their enterprise.

February 24, 2007 at 11:06 PM  
Blogger sink sink socks said...

Throckmorton, who forgot the subject ofwhich she strumpfhosen storys spoke, as soon as she asked the question, is quitesatisfied.Master Horner bethought him of the kostenloser download von pornos successive killing-times, andconsequent doughnuts of the twenty families in which he had sojournedthe years before, and consented to the exaction.We are, on other grounds, justified in connecting thedisagreeable character of all these dreams with the fact of dreamdisfigurement, video porno and in concluding that these dreams are distorted, andthat the wish-fulfillment in them is disguised until recognition isimpossible for no other reason than that a repugnance, a will tosuppress, exists in relation to the subject-matter of the dream or inrelation to the wish which the dream creates.Accidental and indifferentmatters, or what must appear so to the child, find no acceptance in thecontents of fickbilder sex the dream.

March 7, 2007 at 11:08 PM  
Blogger sink sink socks said...

Thus Ihave avoided stating whether I connect with sexkontakte von senioren the word suppressedanother sense than with the word repressed.He'd give him wer wichs mir einen a little punch behind, and the nextminute you'd see that frog whirling in the air like a doughnut--seehim turn one summerset, or may be a couple, if he got a good start,and come down flat-footed and all right, like a cat.Bredesobbed on her shoulder, why didn't you tell us?W-W-W-We didn't want to be t-t-taken for a b-b-b-b-bridal couple,sobbed Mrs saunaclub nrw.There, whenever I chanced tolook, I saw him kneel free schlampen free porno video and pray; and there, by day and by night, afuneral hymn was chanted.

March 15, 2007 at 1:26 AM  
Blogger sink sink socks said...

Dream symbolism leads us far beyond the dream; it does not belong onlyto dreams, but is likewise dominant in legend, myth, and saga, in witand in Wie geht mastubieren folklore.Ah--er--not the finest bourbon whiskey, selected by meine sex bilder aKentucky friend? No? Pardon me! A cigar, then--the mildest Havana.My friends seemed to think it was I; butI felt, that, as Dennis had done the popular thing, he was entitled tothe honor; titten erotik so I sent him to Augusta when the time came, and he tookthe oaths.In this connection it may be remarked that thissymbolism does not belong peculiarly to the dream, but rather tounconscious thinking, particularly that of the masses, and it is to befound in greater perfection in the folklore, in the myths, legends, andmanners of speech, in the proverbial sayings, and in the currentwitticisms of a nation than omasexkontakte in its dreams.

March 26, 2007 at 12:29 AM  
Blogger sink sink socks said...

He went out upon the platform www and threw back hishead, sniffing the soft breeze, heavy with the mysterious thrill ofunplowed acres, the wondrous existence of primordial jungle, wherelife has rioted unceasingly above unceasing decay.The elder www was laboriously assorting these postscriptcommissions in his memory, well knowing that to return with any one ofthem neglected would cause trouble in the family circle.This puzzle had led him to notunfrequent ruminations in his mind www as to whether or not his vocationmight lie in something higher than the mere tilling of the ground.Indeed, the fading of memories and the flaggingof affects, www which we are apt to take as self-evident and to explain as aprimary influence of time on the psychic memories, are in realitysecondary changes brought about by painstaking work.

March 30, 2007 at 12:03 AM  

Post a Comment

<< Home