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 Subject: Re: looping through a list, starting at 1 References: 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: 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 Stefan Ram 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 it = l.iterator(); it.next(); // skip first (assuming a list has ...) while (it.hasNext()) { final E e = it.next(); ... }