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.
List.reversed returns value of type Iterable<E>
.
In this example,
numbers
containing the integers [1, 2, 3]
.reversed
property to get an iterable of the numbers in reverse order.reversedNumbers
.void main() {
List<int> numbers = [1, 2, 3];
Iterable<int> reversedNumbers = numbers.reversed;
print('Reversed numbers: $reversedNumbers'); // Output: Reversed numbers: (3, 2, 1)
}
Reversed numbers: (3, 2, 1)
In this example,
characters
containing the characters ['a', 'b', 'c']
.reversed
property to get an iterable of the characters in reverse order.reversedCharacters
.void main() {
List<String> characters = ['a', 'b', 'c'];
Iterable<String> reversedCharacters = characters.reversed;
print('Reversed characters: $reversedCharacters'); // Output: Reversed characters: (c, b, a)
}
Reversed characters: (c, b, a)
In this example,
strings
containing the strings ['apple', 'banana', 'cherry']
.reversed
property to get an iterable of the strings in reverse order.reversedStrings
.void main() {
List<String> strings = ['apple', 'banana', 'cherry'];
Iterable<String> reversedStrings = strings.reversed;
print('Reversed strings: $reversedStrings'); // Output: Reversed strings: (cherry, banana, apple)
}
Reversed strings: (cherry, banana, apple)
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.