Newbie question: make arrayList to allow only unique values

U

usgog

Is there an elegant way to make an arrayList to allow only unique
values, like Map? I can use Map for that but I don't want to generate
many "fake" keys for keeping unique values of value.
 
O

Oliver Wong

Is there an elegant way to make an arrayList to allow only unique
values, like Map? I can use Map for that but I don't want to generate
many "fake" keys for keeping unique values of value.

Each type of collection has different properties. For example, Lists
maintain the order of their elements, while Sets ensure no duplicate values.
If you only care about no duplicates, and don't care about the order of the
elements, use a Set as someone else suggested. Otherwise, please state which
properties you desire, so that a suitable datastructure can be recommended.

- Oliver
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,268
Messages
2,571,096
Members
48,773
Latest member
Kaybee

Latest Threads

Top