Showing posts with label Java TreeSet missing elements. Show all posts
Showing posts with label Java TreeSet missing elements. Show all posts

Tuesday, August 4, 2009

Java TreeSet missing elements

If you notice that some elements may be missing after having added them to a TreeSet then it is probably because your implementation of Comparator or Comparable is incorrect.

This is the key note to remember:

"If two elements are different but compareTo returns 0, then TreeSet will consider them equal, and the newly added element replaces the old one".