To sort a list of strings in Dart, you can use the `sort` method.
In this example,
words1
with some strings.sort
method to sort the list in dictionary order.void main() {
List<String> words1 = ['banana', 'apple', 'grape', 'orange'];
words1.sort();
print('Sorted list 1 in dictionary order: \$words1');
}
Sorted list 1 in dictionary order: [apple, banana, grape, orange]
In this example,
words2
with different strings.sort
method to sort this list in dictionary order.void main() {
List<String> words2 = ['pear', 'kiwi', 'lemon', 'apple'];
words2.sort();
print('Sorted list 2 in dictionary order: \$words2');
}
Sorted list 2 in dictionary order: [apple, kiwi, lemon, pear]
In this tutorial, we learned How to Sort a List of Strings in Dictionary Order in Dart language with well detailed examples.