# Visual Basic > Visual Basic FAQs >  Visual Basic .NET - Which Collection Should I Use?

## dday9

*Common Theme*
Which collection should I use to store my values?

*Solution*
The solution that I am going to provide you with is not the final solution and is designed to be a best practices or highly encouraged suggestion.

*Frequently Asked Questions*
_Question 1_. I have a set of values and I know how many there are. No more values will be added and none of the existing values will be removed. What collection should I use?

_Answer_: Use an array. Arrays are fixed sized collections and are highly efficient if you do not need to add or remove values. The following is a code snippet showing how arrays are used:


```
Dim initializedArray() As Integer = {1, 2, 3}

Dim uboundsArray(2) As Integer
uboundsArray(0) = 1
uboundsArray(1) = 2
uboundsArray(2) = 3
```

_Question2_. I have a set of values and I need to have the opportunity to add new values or remove existing values, however I need to be able to add/remove items from any index within the collection. Which collection should I use?

_Answer_: Use a List(Of T). Lists allow you to add/remove items at any index within the collection. The following is a code snippet showing how Lists are used:


```
Dim values As New List(Of Integer)
values.Add(1)
values.AddRange({1, 2, 3})
values.RemoveAt(1)
values.Insert(2, 88)
```

_Question3_. I have a set of values and I need to have the opportunity to add new values or remove existing values, however I want the new values to be added at the end of the collection and the existing values to be removed from the start of the collection. Which collection should I use?

_Answer_: Use a Queue(Of T). Queues represent a FIFO(first-in-first-out) collection which allow you to add new values to the end of the collection and remove existing values from the start of the collection. The following is a code snippet showing how Queues are used:


```
Dim values As New Queue(Of Integer)({1, 2, 3})
values.Dequeue()
values.Dequeue()
values.Enqueue(4)
values.Enqueue(5)
```

_Question4_. I have a set of values and I need to have the opportunity to add new values or remove existing values, however I want the new values to be added at the end of the collection and the existing values to be removed from the end of the collection. Which collection should I use?

_Answer_: Use a Stack(Of T). Stacks represent a LIFO(last-in-first-out) collection which allows you to add new values to the end of a collection and remove existing values from the end of the collection. The following is a code snippet showing how Stacks are used:


```
Dim values As New Stack(Of Integer)({1, 2, 3})
values.Pop()
values.Pop()
values.Push(4)
values.Push(5)
```

_Question5_. I have a set of values that are pairs and I need to have the opportunity to add new values or remove existing values, however the one value in the pair needs to be unique. Which collection should I use?

_Answer_: Use a Dictionary(Of TKey, TValue). Dictionaries represent a collection that stores key/value pairs where the key is a unique value. The following is a code snippet showing how Dictionaries are used:


```
Dim values As New Dictionary(Of Integer, String)
values.Add(1, "a")
values.Add(2, "b")
values.Add(3, "c")
```

_Question6_. I have a set of values that are pairs, however I don't want either the key or value in the pair to have to be unique. Which collection should I use?

_Answer_: Create a custom class to hold your key/value pairs and store them in either an array, a list, a queue, or a stack depending on what you need to do with the collection.

_Question7_. I have a set of values and I need to have the opportunity to add new values or remove existing values, however I need to be able to add/remove items from any index within the collection. To make things more complicated I am targeting a .NET framework that does not support List(Of T). Which collection should I use?

_Answer_: You will still need to use an Array, however you will need to implement the ReDim Preserve operation. ReDim Preserve will redeclare the array while resizing the collection to a new size at the same time preserving the existing values. The following is a code snippet showing how ReDim Preserve is used:


```
Dim initializedArray() As Integer = {1, 2, 3, 4, 5}
ReDim Preserve initializedArray(initializedArray.Length - 3)
```

----------

