This week's giveaway is in the Groovy forum.
We're giving away four copies of Groovy Fundamentals video training course and have Ken Kousen on-line!
See this thread for details.
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 Groovy Fundamentals video training course this week in the Groovy 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: 4530
    
    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.
 
 
subject: Why is this hashmap iterating through an infinite loop?