Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

which one is the best for retreiving elements from a Collection?  RSS feed

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
which I have to use I mean iterator or enhanced for loop if I want to retrieve elements from a collection and where we have to use iterator and enhance for loop? which one is the best one to use in real time projects?



Thanks in advance.
 
Sheriff
Posts: 9613
37
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well when you use enhanced for loop, the compiler actually converts it to a normal for loop with iterator. So actually whether you use enhanced for loop or iterator, both are the same(you cannot modify the collection in both cases otherwise you will get ConcurrentModificationException). It's just that enhanced for loop is more readable when maintaining the code...
 
Rahul Noel
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need more explanation.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!