jQuery in Action, 2nd edition*
The moose likes Beginning Java and the fly likes Why is this hashmap iterating through an infinite loop? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Why is this hashmap iterating through an infinite loop?" Watch "Why is this hashmap iterating through an infinite loop?" New topic
Author

Why is this hashmap iterating through an infinite loop?

Patrick Noah
Greenhorn

Joined: Aug 22, 2011
Posts: 28
I am writing a method to determine whether two strings are anagrams of one another. I am trying to print out the contents of my hashmap to debug it but am encountering an infinite loop. Can someone please tell me why this is happening? Thank you.
Alexander Sales
Ranch Hand

Joined: Feb 21, 2011
Posts: 89

Is this part reliable?



OCPJP 6, OCEWCD Java EE 6
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4370
    
    8

Every time you call iterator() you get a new one, so you reset the position. So you need to keep calling next() on the same Iterator.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Why is this hashmap iterating through an infinite loop?