Getting Started with Vectors

In the following lesson, you will be introduced to Vectors.


Like Lists, Vectors are another immutable collection of sequence type. They differ in the fact that Lists are linear while Vectors are indexed. What this means is that if you want to access a central element in a List, the compiler has to start from the beginning and linearly progress through the List until it finds the element you are trying to access. However, when you want to access a central element in a Vector, the compiler can directly go to that index and access the element in constant time.

While Lists should be used when you only plan to manipulate the head element (first element), Vectors provide efficient access when you want to manipulate elements beyond the head.

Creating a Vector

Vectors can be created using the Vector keyword followed by ().

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy