Saturn
Saturn

Reputation: 18149

Check if ArrayList has a certain index

How do I check if a certain ArrayList index exists?

Upvotes: 1

Views: 15521

Answers (1)

Adam Robinson
Adam Robinson

Reputation: 185643

That depends on what you mean by "exists".

If you mean "If the ArrayList has an index that high", then you need to look at the Count:

If arrayList.Count > yourIndex Then
    ...
End If

If you mean "Does the ArrayList have a value at that index", just check for a null value:

If arrayList(yourIndex) Is Nothing Then
    ...
End If

Upvotes: 7

Related Questions