Dart Tutorials

Dart List reversed
Syntax & Examples

Syntax of List.reversed

The syntax of List.reversed property is:

 Iterable<E> reversed 

This reversed property of List an Iterable of the objects in this list in reverse order.

Return Type

List.reversed returns value of type Iterable<E>.



✐ Examples

1 Get the reversed numbers in the list

In this example,

  1. We create a list named numbers containing the integers [1, 2, 3].
  2. We use the reversed property to get an iterable of the numbers in reverse order.
  3. The reversed numbers are stored in reversedNumbers.
  4. We print the reversed numbers to standard output.

Dart Program

void main() {
  List&lt;int&gt; numbers = [1, 2, 3];
  Iterable&lt;int&gt; reversedNumbers = numbers.reversed;
  print('Reversed numbers: $reversedNumbers'); // Output: Reversed numbers: (3, 2, 1)
}

Output

Reversed numbers: (3, 2, 1)

2 Get the reversed characters in the list

In this example,

  1. We create a list named characters containing the characters ['a', 'b', 'c'].
  2. We use the reversed property to get an iterable of the characters in reverse order.
  3. The reversed characters are stored in reversedCharacters.
  4. We print the reversed characters to standard output.

Dart Program

void main() {
  List&lt;String&gt; characters = ['a', 'b', 'c'];
  Iterable&lt;String&gt; reversedCharacters = characters.reversed;
  print('Reversed characters: $reversedCharacters'); // Output: Reversed characters: (c, b, a)
}

Output

Reversed characters: (c, b, a)

3 Get the reversed strings in the list

In this example,

  1. We create a list named strings containing the strings ['apple', 'banana', 'cherry'].
  2. We use the reversed property to get an iterable of the strings in reverse order.
  3. The reversed strings are stored in reversedStrings.
  4. We print the reversed strings to standard output.

Dart Program

void main() {
  List&lt;String&gt; strings = ['apple', 'banana', 'cherry'];
  Iterable&lt;String&gt; reversedStrings = strings.reversed;
  print('Reversed strings: $reversedStrings'); // Output: Reversed strings: (cherry, banana, apple)
}

Output

Reversed strings: (cherry, banana, apple)

Summary

In this Dart tutorial, we learned about reversed property of List: the syntax and few working examples with output and detailed explanation for each example.