3

I have a JList that holds a bunch of strings . I would like it to act like a Set , so that it will only hold unique values . Is there any way to achieve this without checking that a new string doesn't already exist there ?

Geo
  • 93,257
  • 117
  • 344
  • 520
  • To what purpose? Is it necessary to iterate in the order items were added? Is it necessary to randomly access the items? Why does a set not work for you? – Lawrence Dol Nov 24 '08 at 00:48

1 Answers1

5

take a look at the docs: 1.4.2 | Java 6

You can set your own ListModel via JList#setModel(ListModel) which might be backed by e.g. a HashSet instead of the Vector which is used by default.

See also ListModel and AbstractListModel

Argelbargel
  • 5,840
  • 2
  • 23
  • 16