Is there a no-duplicate List implementation out there?

后端 未结 11 642
悲哀的现实
悲哀的现实 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 00:56

    There's no Java collection in the standard library to do this. LinkedHashSet preserves ordering similarly to a List, though, so if you wrap your set in a List when you want to use it as a List you'll get the semantics you want.

    Alternatively, the Commons Collections (or commons-collections4, for the generic version) has a List which does what you want already: SetUniqueList / SetUniqueList.

提交回复
热议问题