Is there a no-duplicate List implementation out there?

后端 未结 11 701
悲哀的现实
悲哀的现实 2020-11-29 00:53

I know about SortedSet, but in my case I need something that implements List, and not Set. So is there an implementation out there, in the API or e

11条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-29 01:14

    Off the top of my head, lists allow duplicates. You could quickly implement a UniqueArrayList and override all the add / insert functions to check for contains() before you call the inherited methods. For personal use, you could only implement the add method you use, and override the others to throw an exception in case future programmers try to use the list in a different manner.

提交回复
热议问题