java TreeSet - don't remove duplicate items

pengguang001 picture pengguang001 · May 5, 2011 · Viewed 17.9k times · Source

TreeSet removes different items with the same Comprator value. I don't want it be removed. Is there any way to control this? Or use another container class?

Added: OK. It seems I can't use Set. I need insert sorting feature, for performance consideration. Can List do this? Thanks all.

Answer

Heiko Rupp picture Heiko Rupp · May 5, 2011

A set by definition can not have duplicate entries.

So you need to use a List or Array or such