Home » Scala Vector

Scala Vector

Vector is a general-purpose, immutable data structure. It provides random access of elements. It is good for large collection of elements.

It extends an abstract class AbstractSeq and IndexedSeq trait.


Scala Vector Example

Output:

Vector(5, 8, 3, 6, 9, 4)  Vector(5, 2, 6, 3)  Vector(  

Scala Vector Example

In the following example, we have created a vector. You can also add new element and merge two vectors.

Output:

Vector Elements: Hocky Cricket Golf   Vector Elements after adding: Hocky Cricket Golf Racing   Vector Elements after merging: Hocky Cricket Golf Racing Swimming   Vector Elements after reversing: Swimming Racing Golf Cricket Hocky   Vector Elements after sorting: Cricket Golf Hocky Racing Swimming  
Next TopicScala List

You may also like