In this quick article, we’ll see how to remove the last element from a list in Kotlin.

Kotlin MutableList efficiently supports deletion at the end. This can be done in several ways, as shown below:

1. Using removeLast() function

The simplest solution to remove the last element from a list in Kotlin is to use the removeLast() function.

Download Code

2. Using removeAt() function

You can also use the removeAt() function, which removes an element from the specified position in the list. To remove the last element, you need to pass an index of the last element.

Download Code

3. Using remove() function

If your list contains all distinct elements, you can call the remove() function with the last element. This removes the first occurrence of the last element from the list.

That’s all about removing the last element of a list in Kotlin.