list datatype in java which dosen't add duplicates
Is there any list datatype in java which dosen't add duplicates. I am not worried about the开发者_StackOverflow order in which they are inserted in the list but I would like to have a list which dosen't add duplicates. Or might be the case if the same element is present it just overrites it. Is there something already build in JDK or might be in apache commons package.
You're looking for a HashSet<T>
.
If you don't want reference equality, you'll need to override equals()
and hashCode()
.
精彩评论