Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which collection for storing unique strings?

I'm looking for a collection just like Dictionary(OF Key, Value) but I don't actually need a key and value. Key itself is enough. So something like Collection(Key). It shouldn't accept duplicate keys.

I've looked up couple of collections in .NET Framework but couldn't find what I want. Currently I'm abusing Dictionary(OF String, String) and setting Value as Nothing all the time.

Shall I just continue abusing Dictionary(OF T,T)?

like image 201
dr. evil Avatar asked Mar 28 '09 14:03

dr. evil


People also ask

Which collection is used to store unique values of strings in a variable?

HashSets are used to store a collection of unique elements. HashSet cannot contain duplicate values. HashSet allows null value.

How to store unique values of string in Java?

Store unique values in Java using Set interface The Set interface in Java allows allows maintaining unique list in Java. Here in this example we will use HashSet to maintain list of of unique values in our program. First of all we will initialize the HashSet object and then add few values including duplicates.

Which collection does not allow duplicates in C#?

Thus, HashSet is a generic collection, that does not allow duplicates.


2 Answers

I think what you want is a HashSet<T>.

like image 189
tvanfosson Avatar answered Oct 15 '22 01:10

tvanfosson


HashSet<T> would work for this. It lets you store a unique set of values, without "abusing" a dictionary.

like image 43
Reed Copsey Avatar answered Oct 14 '22 23:10

Reed Copsey