Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #6719
| 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> |
| Message-ID | <slrnj3ed7f.6gl.avl@gamma.logic.tuwien.ac.at> (permalink) |
| Date | 2011-08-01 23:21 +0000 |
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
Re: looping through a list, starting at 1 Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-01 23:21 +0000
csiph-web