• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

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: 22821
132
Eclipse IDE Spring 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: 80226
424
  • 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.
 
Sheriff
Posts: 28364
99
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: 22821
132
Eclipse IDE Spring 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: 13091
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
Sheriff
Posts: 28364
99
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: 22821
132
Eclipse IDE Spring 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.
 
You can't expect to wield supreme executive power just because
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic