Javatpoint Logo
Javatpoint Logo

VB.NET ArrayList

Collection Classes

The collection classes are special-purpose classes that are useful for storing data, dynamically allocating memory, retrieving a list of items or elements on the basic index number, etc. Furthermore, the collection classes also support Lists, ArrayList, Hash tables, queues, stacks, etc. that apply to the same interface.

ArrayList

The arrayList is an ordered collection of data elements that can be indexed individually in a list. The flexible data structure allows multiple objects to be added in a list without any size information. It is similar to the array. With the use of indexes in the ArrayList, we can add or remove an element from the list's specified location. Further, it also allows search, sort, add, and dynamic memory allocation in the ArrayList.

Uses of ArrayList

The following are the important uses of the ArrayList object.

1. Add: Add a data element to ArrayList.

Syntax:

2. Insert: Insert data element at specified location of ArrayList.

Syntax:

3. Remove: Remove an element from ArrayList.

Syntax:

4. RemoveAt: Remove data elements from the specified location of ArrayList.

Syntax:

indexNo: It represents the specified position of the item to be removed from the ArrayList.

5. Sort(): As the name suggests, it is used to sort all elements of the ArrayList.

Syntax:

Properties of the ArrayList Class

Following are the property of the ArrayList Class in the VB.NET

Property name Description
Capacity It is used to get all elements of the ArrayList.
IsFixedSize It gets a value that determines if the ArrayList has a fixed size.
Count It is used to count the number of elements available in the ArrayList.
IsReadOnly It returns the value that verifies if the ArrayList is read-only.
Item It is used to get or set an item at a specified position in the ArrayList.

Methods of the ArrayList class

Following are the various methods of the ArrayList Class in the VB.NET

Method Name and their description

1. Add() Method: The Add() function is used to add an item to the end of the ArrayList.

Syntax:

2. Clear() Method: The Clear() method is used to clear all the elements from the ArrayList

Syntax:

3. Insert() Method: The Insert() method is used to insert an element into the specified location of the ArrayList.

Syntax:

4. Contains() Method: The Contains() Method is used to check whether the specified element exists in the ArrayList.

Syntax:

5. Remove() Method: The Remove() Method is used to remove a specified element from the ArrayList.

Syntax:

6. InsertRange() Method: The InsertRange() method is used to insert the collections of elements at the specified location in the ArrayList.

Syntax:

7. RemoveRange() Method: The RemoveRange() method is used to set a range for removing the elements from the ArrayList.

Syntax:

8. Reverse() Method: The Reverse() Method is used to reverse the order of the elements to the ArrayList.

Syntax:

9. RemoveAt() Method: The RemoveAt() method is used to remove an array element from the specified index of the ArrayList.

Syntax:

Let's create a program to understand the various function of ArrayList in the VB.NET programming language.

AList.vb

Output:

VB.NET ArrayList
Next TopicVB.NET HashTable





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA