List myList = ['John', 'herry', 'Carl', 'Morgan'];
myList = myList.reversed.toList();
print(myList);
Output
[Morgan, Carl, herry, John]
The reversed keyword is used to reverse the list and after that, we can use the toList() function to convert the output from List.reverse to a list in Dart.
Another Code Example
List numbers = [10, 20, 30, 40, 50];
List result = numbers.reversed.toList();
print(result);
Output
[50, 40, 30, 20, 10]
0 Comments