One of the most common problems we face while working with arrays is that we need to know the size of the array during its initialization. It isn't possible to know the size of the array up-front during its initialization. Imagine a case where you're building a social networking project, and you're trying to fetch all of the friends of a particular user from the server and display these in the UI. The number of friends that a user has can't be known unless we get the response from the server. These kinds of situations can be handled using vectors.
A vector is nothing but a data structure backed by an array, which can grow in size when required. Let's try to build a simple implementation of the Vector class to understand it more:
class Vector <E> {
private val minCapacityIncrement = 12
var elements: Array <Any?>...