Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #6930
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!.POSTED!not-for-mail |
|---|---|
| From | Jan Burse <janburse@fastmail.fm> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: setSize ArrayList, when will it come? |
| Date | Wed, 10 Aug 2011 00:36:03 +0200 |
| Organization | albasani.net |
| Lines | 50 |
| Message-ID | <j1scom$shp$1@news.albasani.net> (permalink) |
| References | <j1pp1j$3rf$1@news.albasani.net> <ojp247dlgld0hso4hkamufus1jr0hd6m7t@4ax.com> <1eadnROad6gX8NzTnZ2dnUVZ_tydnZ2d@earthlink.com> <alpine.DEB.2.00.1108092230010.20857@urchin.earth.li> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Trace | news.albasani.net I9YqJFKz4u3UC9EdNUaDr/0uu8Ad7d4t+7Qj6IY9LblG71GgqfHM/hKNOH8GfDmdqdedtM0h7VycvIdot8RZHg== |
| NNTP-Posting-Date | Tue, 9 Aug 2011 22:36:06 +0000 (UTC) |
| Injection-Info | news.albasani.net; logging-data="ezuHTEoTejDN2slpWHZhu75QPZsN3BDhg4BAlc/fqR9MFdrQxnQLc2qh/vvh2OBZu4Jpp1PRgAIlbQnKdZNZQOq3NSm+u6xrTxppX4Kz57ZukD5Szn7mgc1xkKnXcWO3"; 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 | <alpine.DEB.2.00.1108092230010.20857@urchin.earth.li> |
| Cancel-Lock | sha1:nhdSzyjHq0vg8XkcPNqqOwdHVEA= |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:6930 |
Show key headers only | View raw
Tom Anderson schrieb:
> On Tue, 9 Aug 2011, Patricia Shanahan wrote:
>
>> 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.
>
> It would be nice if ArrayList used a loop to do the copy for small added
> collections; it could cut over to the array method for larger addends.
>
> Anyway, with List.addAll and Collections.nCopies, we can write:
>
> <T> void setSize(List<T> list, int size) {
> int change = size - list.size();
> if (change > 0) {
> list.addAll(Collections.nCopies(change, null));
> }
> else if (change < 0) {
> list.subList(size, list.size()).clear();
> if (list instanceof ArrayList) ((ArrayList)list).trimToSize();
> }
> // else do nothing
> }
>
> I haven't tried that, but it should work.
>
> So, Jan, less whining, more coding, please.
>
> tom
>
This is not efficient. You don't get it what the
problem is. I really really need a highly efficient
setSize() specialized, otherwise my stuff will not work.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar
setSize ArrayList, when will it come? Jan Burse <janburse@fastmail.fm> - 2011-08-09 00:47 +0200
Re: setSize ArrayList, when will it come? Knute Johnson <september@knutejohnson.com> - 2011-08-08 16:53 -0700
Re: setSize ArrayList, when will it come? Jan Burse <janburse@fastmail.fm> - 2011-08-09 02:30 +0200
Re: setSize ArrayList, when will it come? Arne Vajhøj <arne@vajhoej.dk> - 2011-08-08 20:50 -0400
Re: setSize ArrayList, when will it come? Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-08-08 21:09 -0400
Re: setSize ArrayList, when will it come? Jan Burse <janburse@fastmail.fm> - 2011-08-09 04:16 +0200
Re: setSize ArrayList, when will it come? Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-08-08 21:39 -0500
Re: setSize ArrayList, when will it come? Jan Burse <janburse@fastmail.fm> - 2011-08-09 09:33 +0200
Re: setSize ArrayList, when will it come? Jan Burse <janburse@fastmail.fm> - 2011-08-09 09:42 +0200
Re: setSize ArrayList, when will it come? Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-09 07:56 +0000
Re: setSize ArrayList, when will it come? Jan Burse <janburse@fastmail.fm> - 2011-08-09 11:18 +0200
Re: setSize ArrayList, when will it come? Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-08-09 10:36 -0500
Re: setSize ArrayList, when will it come? Jan Burse <janburse@fastmail.fm> - 2011-08-09 18:30 +0200
Re: setSize ArrayList, when will it come? Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-08-09 16:30 -0500
Re: setSize ArrayList, when will it come? Jan Burse <janburse@fastmail.fm> - 2011-08-10 00:31 +0200
Re: setSize ArrayList, when will it come? Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-08-09 20:36 -0500
Re: setSize ArrayList, when will it come? Jan Burse <janburse@fastmail.fm> - 2011-08-10 09:04 +0200
Re: setSize ArrayList, when will it come? Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-10 08:50 +0000
Re: setSize ArrayList, when will it come? Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-08-10 18:16 -0500
Re: setSize ArrayList, when will it come? Jan Burse <janburse@fastmail.fm> - 2011-08-11 01:55 +0200
Re: setSize ArrayList, when will it come? Patricia Shanahan <pats@acm.org> - 2011-08-09 01:33 -0700
Re: setSize ArrayList, when will it come? Jan Burse <janburse@fastmail.fm> - 2011-08-09 11:16 +0200
Re: setSize ArrayList, when will it come? Jan Burse <janburse@fastmail.fm> - 2011-08-09 11:32 +0200
Re: setSize ArrayList, when will it come? Jan Burse <janburse@fastmail.fm> - 2011-08-09 11:35 +0200
Re: setSize ArrayList, when will it come? Patricia Shanahan <pats@acm.org> - 2011-08-09 04:00 -0700
Re: setSize ArrayList, when will it come? Arne Vajhøj <arne@vajhoej.dk> - 2011-08-09 20:11 -0400
Re: setSize ArrayList, when will it come? Robert Klemme <shortcutter@googlemail.com> - 2011-08-10 10:21 +0200
Re: setSize ArrayList, when will it come? Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-10 09:14 +0000
Re: setSize ArrayList, when will it come? Jan Burse <janburse@fastmail.fm> - 2011-08-10 12:29 +0200
Re: setSize ArrayList, when will it come? Robert Klemme <shortcutter@googlemail.com> - 2011-08-10 19:27 +0200
Re: setSize ArrayList, when will it come? Jan Burse <janburse@fastmail.fm> - 2011-08-10 20:22 +0200
Re: setSize ArrayList, when will it come? Jan Burse <janburse@fastmail.fm> - 2011-08-10 20:37 +0200
Re: setSize ArrayList, when will it come? Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-08-10 18:22 -0500
Re: setSize ArrayList, when will it come? Jan Burse <janburse@fastmail.fm> - 2011-08-11 01:52 +0200
Re: setSize ArrayList, when will it come? Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-08-10 21:43 -0500
Re: setSize ArrayList, when will it come? Jan Burse <janburse@fastmail.fm> - 2011-08-11 14:19 +0200
Re: setSize ArrayList, when will it come? Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-10 22:23 +0000
Re: setSize ArrayList, when will it come? Jan Burse <janburse@fastmail.fm> - 2011-08-11 01:47 +0200
Re: setSize ArrayList, when will it come? Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-11 00:23 +0000
Re: setSize ArrayList, when will it come? Jan Burse <janburse@fastmail.fm> - 2011-08-11 09:19 +0200
Re: setSize ArrayList, when will it come? Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-12 15:06 +0000
Re: setSize ArrayList, when will it come? Roedy Green <see_website@mindprod.com.invalid> - 2011-08-09 09:58 -0700
Re: setSize ArrayList, when will it come? Patricia Shanahan <pats@acm.org> - 2011-08-09 10:25 -0700
Re: setSize ArrayList, when will it come? Tom Anderson <twic@urchin.earth.li> - 2011-08-09 22:38 +0100
Re: setSize ArrayList, when will it come? Jan Burse <janburse@fastmail.fm> - 2011-08-10 00:36 +0200
Re: setSize ArrayList, when will it come? Roedy Green <see_website@mindprod.com.invalid> - 2011-08-09 15:55 -0700
Re: setSize ArrayList, when will it come? Knute Johnson <september@knutejohnson.com> - 2011-08-09 16:03 -0700
Re: setSize ArrayList, when will it come? Jan Burse <janburse@fastmail.fm> - 2011-08-10 09:18 +0200
Re: setSize ArrayList, when will it come? Mayeul <mayeul.marguet@free.fr> - 2011-08-10 11:26 +0200
Re: setSize ArrayList, when will it come? Jan Burse <janburse@fastmail.fm> - 2011-08-10 12:35 +0200
Re: setSize ArrayList, when will it come? Lew <lewbloch@gmail.com> - 2011-08-10 09:33 -0700
Re: setSize ArrayList, when will it come? Jan Burse <janburse@fastmail.fm> - 2011-08-10 20:22 +0200
Re: setSize ArrayList, when will it come? Patricia Shanahan <pats@acm.org> - 2011-08-09 22:13 -0700
Re: setSize ArrayList, when will it come? Jan Burse <janburse@fastmail.fm> - 2011-08-11 02:01 +0200
Re: setSize ArrayList, when will it come? Patricia Shanahan <pats@acm.org> - 2011-08-10 18:42 -0700
Re: setSize ArrayList, when will it come? Jan Burse <janburse@fastmail.fm> - 2011-08-11 14:21 +0200
Re: setSize ArrayList, when will it come? Arne Vajhøj <arne@vajhoej.dk> - 2011-08-09 20:09 -0400
Re: setSize ArrayList, when will it come? Roedy Green <see_website@mindprod.com.invalid> - 2011-08-09 16:02 -0700
Re: setSize ArrayList, when will it come? Arne Vajhøj <arne@vajhoej.dk> - 2011-08-09 20:13 -0400
csiph-web