Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail NNTP-Posting-Date: Tue, 09 Aug 2011 12:25:30 -0500 Date: Tue, 09 Aug 2011 10:25:31 -0700 From: Patricia Shanahan User-Agent: Mozilla/5.0 (Windows NT 5.2; WOW64; rv:5.0) Gecko/20110624 Thunderbird/5.0 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Re: setSize ArrayList, when will it come? References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <1eadnROad6gX8NzTnZ2dnUVZ_tydnZ2d@earthlink.com> Lines: 19 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 70.230.203.65 X-Trace: sv3-AEaTjxPC3JGG5ehiSMfem56hOuu/CEZjlUPYQQVek8SywADy7OrvWYrzfeEVSX3rDCEXXSwQ32M6QuH!nD+rswtTYXsMuhN1Ca+6ze8MG7sp4DZmhO7FRzZ/+yh1qRRRGB0vBoPol2s1IqX68mM4R8S9aX2a!5c+w/BOolpOFyzQj5BEKTHQAIusjBYekiysnpOtzs5a1Bg== X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 1791 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:6921 On 8/9/2011 9:58 AM, Roedy Green wrote: ... > Further, I would hope ArrayList.addAll would be smart enough to grow > the array only once, if needed. ... It does the following: 1. Grow to the needed size. 2. Call the other collection's toArray method. 3. System.arraycopy the toArray result into the ArrayList's elementData. This double copy is going to be faster than the one at a time approach only if large numbers of nulls are being added. If that is the case, the structure is probably too sparse for ArrayList to be a good choice. Patricia