Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Kotlin

Idiom #19 Reverse a list

Reverse the order of the elements of the list x.
This may reverse "in-place" and destroy the original ordering.

x = x.reversed()

Immutable lists but not in-place.
val reversedView = x.asReversed()

Returns a reversed read-only view of the original List. All changes made in the original list will be reflected in the reversed one.
x.reverse()

MutableLists or Arrays can be reversed in place.
with Ada.Containers.Vectors;
use Ada.Containers;
X.Reverse_Elements;

New implementation...
< >
programming-idioms.org