Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #6719

Re: looping through a list, starting at 1

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.dougwise.org!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!news.in2p3.fr!in2p3.fr!kanaga.switch.ch!switch.ch!newscore.univie.ac.at!aconews-feed.univie.ac.at!aconews.univie.ac.at!not-for-mail
Newsgroups comp.lang.java.programmer
From Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at>
Subject Re: looping through a list, starting at 1
References <list-20110802003845@ram.dialup.fu-berlin.de>
Reply-To avl@logic.at
User-Agent slrn/pre0.9.9-111 (Linux)
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 8bit
Message-ID <slrnj3ed7f.6gl.avl@gamma.logic.tuwien.ac.at> (permalink)
Date 01 Aug 2011 23:21:19 GMT
Lines 21
NNTP-Posting-Host gamma.logic.tuwien.ac.at
X-Trace 1312240879 tunews.univie.ac.at 71616 128.130.175.3
X-Complaints-To abuse@tuwien.ac.at
Xref x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:6719

Show key headers only | View raw


Stefan Ram <ram@zedat.fu-berlin.de> wrote:
>   Assuming a list has a sufficient number of entries at run
>   time, what should be prefered to assign a reference to each
>   entry to »e«, starting at index 1:

> for( final E e : l.sublist( 1, l.size() ))...
This appears to be the most elegant and general approach.

> for( int i = 1; i < l.size(); ++i ){ final E e = l.get( 0 ); ... }
for an ArrayList-like implementation, this one may perform well,
while for a LinkedList-alike it will scale rather bad for large lists.

Another option would be to get an iterator from your list, pre-advance
it once, then use a while-loop on it.hasNext() ...
   Iterator<E> it = l.iterator();
   it.next(); // skip first (assuming a list has ...)
   while (it.hasNext()) {
      final E e = it.next();
      ...
   }

Back to comp.lang.java.programmer | Previous | Next | Find similar


Thread

Re: looping through a list, starting at 1 Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-01 23:21 +0000

csiph-web