TreeSet ordering can drop entries
TreeSet uses compareTo or its Comparator to determine both order and apparent equality. A comparator returning zero for distinct objects causes one to be discarded.
TreeMap.putkeeps the original key when the comparator returns zero, so the new key object is silently not stored. If you have hit a variant of this, share it below."TreeSet ordering can drop entries" is a useful thing to know about with java / treeset. Thanks for sharing it.
A TreeSet treats any two elements that compare as zero as duplicates, so the second one is never stored. Make the comparator break ties on a unique field so that distinct objects remain.
TreeSet relies on the comparator for equality as well as order, so a zero return drops the newer element silently. A tie-breaker on an identifying field prevents distinct entries from colliding.
When compare returns zero for objects that are not really equal, TreeSet keeps only the first. Adding a secondary key to the comparison keeps all of them.
Good to see "TreeSet ordering can drop entries" written down. Handy reference for anyone working with java / treeset.
Good to see "TreeSet ordering can drop entries" written down. Handy reference for anyone working with java / treeset.
"TreeSet ordering can drop entries" is a useful thing to know about with java / treeset. Thanks for sharing it.
Good to see "TreeSet ordering can drop entries" written down. Handy reference for anyone working with java / treeset.