• Post Reply Bookmark Topic Watch Topic
  • New Topic

Sorting the HashMap failed with TreeMap class  RSS feed

 
vinoth vino
Ranch Hand
Posts: 67
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends, I m new to java collections and i m stuck in hashMap sorting. Here, i am using TreeMap class to sort the HashMap based on their keys
But it won't display elements which are present in the TreeMap class. What's wrong with my Code? Please Kindly anyone help me...



OUTPUT
Before Sorting
Key : 0 Value : ffff
Key : 2 Value : vino
Key : 4 Value : sddf
Key : 9 Value : vvil
Key : 12 Value : qwert
After Sorting
Exception in thread "main" java.util.NoSuchElementException
at java.util.HashMap$HashIterator.nextNode(Unknown Source)
at java.util.HashMap$EntryIterator.next(Unknown Source)
at java.util.HashMap$EntryIterator.next(Unknown Source)
at NewClass.main(NewClass.java:28)
HashMap-sorting-output.png
[Thumbnail for HashMap-sorting-output.png]
 
Paweł Baczyński
Bartender
Posts: 2083
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look carefully at line 28. Which Iterator are you calling next() on?
 
vinoth vino
Ranch Hand
Posts: 67
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I want to call "it2"
Thank you
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!