• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

enhanced for loop backward traversal

 
Ranch Hand
Posts: 238
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I read as backward traversal is not possible in enhanced for loop. I was not clear on that. Any ideas, resources, links, sample code highly appreciated. thanks in advance
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, that's true. But what can possibly be unclear about that? Can't be done, sounds pretty clear to me. What kinds of links were you looking for to expand on that? And what kind of sample code could possibly be written for something which can't be done?
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well there is no forward or backward traversal for the enhanced for-loop. An enhanced for loop uses an Iterator to traversal through a data-source. It doesn't matter if the Iterator goes through the data-source forward, backward or criss cross.
 
Master Rancher
Posts: 4806
72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, this can be done pretty easily with Guava:

The object returned by Lists.reverse() is a view of the underlying list. If you look at how it implements iterator(), you should find that it returns an Iterator that is actually using a ListIterator and is using it in reverse.
reply
    Bookmark Topic Watch Topic
  • New Topic