• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to covert each loop into simple for loop?

 
Chitta Ranjan Mahato
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Experts,

Please covert the below code into simple for loop.


Thanks in advance.
Chitta Ranjan .

 
Rob Spoor
Sheriff
Pie
Posts: 20494
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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?
 
Campbell Ritchie
Sheriff
Posts: 48382
56
  • Mark post as helpful
  • send pies
  • 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.
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes i think there is no need of for loop here..Go through the HashMap documentation.
 
Paul Clapham
Sheriff
Pie
Posts: 20735
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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
Pie
Posts: 20494
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12084
29
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • 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
Pie
Posts: 20735
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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
Pie
Posts: 20494
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic