Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!.POSTED!not-for-mail From: Jan Burse Newsgroups: comp.lang.java.programmer Subject: Re: setSize ArrayList, when will it come? Date: Wed, 10 Aug 2011 12:35:23 +0200 Organization: albasani.net Lines: 28 Message-ID: References: <1eadnROad6gX8NzTnZ2dnUVZ_tydnZ2d@earthlink.com> <4e424e40$0$20391$426a74cc@news.free.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.albasani.net oqK5u0ReU0DsGr3J/oEyllASLMOtXBknuX/MjzJM4fKqeGRGrQjzTgw5filQ+hw4ppFCJh53SZcFoQyZpCnrZMeyQCxACStEo0YHC3ThHr13Z57gFUBC3TfBnQGSSB4s NNTP-Posting-Date: Wed, 10 Aug 2011 10:35:27 +0000 (UTC) Injection-Info: news.albasani.net; logging-data="mEbn4CQu3ceqjZb6yTgdd9aPqw6pcZ8GuOmfADOj2kPPU/GmIO7HmWyG2HnICbKzEpHDjGsW3e5l49BANRRUSHhQgGPvvwl/QR4R0rMPEYTNNuzZZbP+NA5BCpowufhv"; mail-complaints-to="abuse@albasani.net" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20110706 Firefox/5.0 SeaMonkey/2.2 In-Reply-To: <4e424e40$0$20391$426a74cc@news.free.fr> Cancel-Lock: sha1:vsUDERWu4zKsFcrBe+JczVcOjNM= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:6967 Mayeul schrieb: >> >> So there are 10 temporary array allocations, until >> we reach the final array. Also the resultinhg elementData >> has 39 excess place holders which I don't need. > > Nope Yes that you are right, since array list does override the addAll method, and there they do set the size correctly. But a new object pops up there. The CopiesList is materialized. Here you see the code: public boolean addAll(Collection c) { Object[] a = c.toArray(); int numNew = a.length; ensureCapacity(size + numNew); // Increments modCount System.arraycopy(a, 0, elementData, size, numNew); size += numNew; return numNew != 0; } So there are two temporary objects, the CopiesList, and the Object[] a from above. No enumerator. Not nice