Home > Back-end >  How to reverse an ArrayList in Kotlin?
How to reverse an ArrayList in Kotlin?

Time:10-05

I am trying to reverse an ArrayList using reversed method but its return type is List. I want ArrayList as return type as I have to pass the ArrayList into the RecyclerView Adapter

CodePudding user response:

Just call reverse() on it. There is no return type (other than Unit) because it modifies the original list. Maybe you were looking at reversed() which creates a reversed copy of the list.

This answer has some helpful information on how to interpret the meaning of the English grammar used in standard library collection functions.

  • Related