my dog learned polymorphism*
The moose likes Beginning Java and the fly likes how to covert  each loop  into simple for loop? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how to covert  each loop  into simple for loop?" Watch "how to covert  each loop  into simple for loop?" New topic
Author

how to covert each loop into simple for loop?

Chitta Ranjan Mahato
Ranch Hand

Joined: Jun 20, 2009
Posts: 38
Dear Experts,

Please covert the below code into simple for loop.


Thanks in advance.
Chitta Ranjan .

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

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?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38057
    
  22
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

Joined: Mar 17, 2010
Posts: 1051

Yes i think there is no need of for loop here..Go through the HashMap documentation.


SCJP6.0,My blog Ranchers from Delhi
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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

Joined: Oct 27, 2005
Posts: 19655
    
  18

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

Joined: Oct 02, 2003
Posts: 11169
    
  16

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


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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

Joined: Oct 27, 2005
Posts: 19655
    
  18

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to covert each loop into simple for loop?
 
Similar Threads
put float into hashMap
integer from properties file
Type safety: Unchecked cast from Object to List<String>
Using Generics, HashMap with two different objects as Keys
convert "forty five" to "45"