Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why is this hashmap iterating through an infinite loop?

 
Patrick Noah
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 89
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this part reliable?

 
Matthew Brown
Bartender
Posts: 4567
8
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic