In Dart programming, the List data type is similar to arrays in other programming languages. A list is used to represent a collection of objects. It is an ordered group of objects. The core libraries in Dart are responsible for the existence of List class, its creation, and manipulation. Sorting of the list depends on the type of list we are sorting i.e. if we are sorting integer list then we can use simple sort function whereas if it is a string list then we use compareTo to sort the list.
Sorting an Integer List
An integer list can be sort by the simple sort function.
Example: Sorting an integer list.
[-389, -11, 0, 2, 13, 32, 142, 3032]
Sorting a String List
The string is sorted by comparing the length in the sort function.
Example: Sorting a string list.
[one, two, four, three]
If we use sort without comparing the length then:
Example: Sorting a string list without comparing the length.
[four, one, three, two]
Example: Using the cascades method while sorting the list.
[-389, -11, 0, 2, 13, 142]
- Dart Programming - List
- Dart - Finding Minimum and Maximum Value in a List
- How to Combine Lists in Dart?
- Basics of Numbers in Dart
- Dart - Super and This keyword
- Dart - Standard Input Output
- Generators in Dart
- Dart - Classes And Objects
- Operators in Dart
- Dart - Loops
- Switch Case in Dart
- Dart - Loop Control Statements (Break and Continue)
- Dart Programming - Functions
- Instance and class methods in Dart
- Abstract Classes in Dart
- Labels in Dart
- Different Types of Functions in Dart
- Dart - Splitting of String
- Method Overriding in Dart
- Concept of Isolates in Dart
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.