This post will discuss various ways to iterate a list in Kotlin in reverse order without actually reversing the list.

1. Using toString() function

If you want to display the contents of the list in reverse order, you can get a reversed read-only view of the original List using the asReversed() function and then print its string representation using the toString() function.

Download Code

2. Using ListIterator

You can use a special iterator ListIterator, that additionally allows bidirectional access over a normal iterator. It takes the starting position on the list.

Download Code

3. Using loop

Since List is an ordered collection, you can use index-based for-loop to access elements by their index in the list. To print the list backward, you can do like:

Download Code

 
You can also call the forEach() function on the reversed read-only view of the original List to print each list element in reverse order.

Download Code

That’s all about iterating a list in reverse order in Kotlin.