• 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:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

For each loop

 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(Question Java Tiger)



concern the code in bold: i guess the method values() is executed once (at the beginning of the loop) and not every time a new value is assigned to variable kolom, because that would be a performance problem
 
Ranch Hand
Posts: 657
Spring VI Editor Clojure
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Values is only called once (in order to get at an Iterator).
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The values() method returns a Collection, and to iterate through that collection an Iterator is obtained from kolommen.values().iterator(). That's done only once, exactly as in the first part of a normal for loop:
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Barry Gaunt:
The values() method returns a Collection, and to iterate through that collection an Iterator is obtained from kolommen.values().iterator(). That's done only once, exactly as in the first part of a normal for loop:



that's exactly what my .class file looks like after i decompiled it (i thought too late about that option to verify my ideas (it's almost weekend so the brain is slowing down )
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic