• 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

how to covert each loop into simple for loop?

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

Please covert the below code into simple for loop.


Thanks in advance.
Chitta Ranjan .

 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I tell you that a for-each loop over a java.lang.Iterable (because that's what's being used in the for-each loop, not java.util.Collection, java.util.List or java.util.Set; those all extend java.lang.Iterable) uses the java.util.Iterator returned by the iterator() method, can you perhaps find the answer yourself?
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why do you want a loop in the first place? Go through the documentation for HashMap and yo ufind something useful.
 
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes i think there is no need of for loop here..Go through the HashMap documentation.
 
Marshal
Posts: 28177
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
I don't understand the question. That for loop looks about as simple as it is possible for a for loop to be.
 
Rob Spoor
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think Chitta wants a for-loop like those of Java 1.4 and before. Having to migrate existing code from Java 5.0/6 to Java 1.4 (for whatever reason) is the only reason I can think of for wanting to convert this loop.
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Spoor wrote:I think Chitta wants a for-loop like those of Java 1.4 and before. Having to migrate existing code from Java 5.0/6 to Java 1.4 (for whatever reason) is the only reason I can think of for wanting to convert this loop.


or it's a simple homework problem
 
Paul Clapham
Marshal
Posts: 28177
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

fred rosenberger wrote:

Rob Spoor wrote:I think Chitta wants a for-loop like those of Java 1.4 and before. Having to migrate existing code from Java 5.0/6 to Java 1.4 (for whatever reason) is the only reason I can think of for wanting to convert this loop.


or it's a simple homework problem



I don't know, it doesn't look like homework to me. But on the other hand I would hate for that code to be real-life production code too.
 
Rob Spoor
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

fred rosenberger wrote:

Rob Spoor wrote:I think Chitta wants a for-loop like those of Java 1.4 and before. Having to migrate existing code from Java 5.0/6 to Java 1.4 (for whatever reason) is the only reason I can think of for wanting to convert this loop.


or it's a simple homework problem


Well, that's part of the reason why I only posted a hint and didn't type out the complete solution.
 
If you are using a rototiller, you are doing it wrong. Even on this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic