Sorting an Integer List

An integer list can be sorted by the simple sort function.

Example: Sorting an integer list.

Dart
// Main function
main() {
  
  // Creating List
  List<int> w3wiki = [13, 2, -11, 142, -389, 32, 3032, 0];
  
  // Sorting List
  w3wiki.sort();
  
  // Printing Sorted List
  print(w3wiki); 
}

Output:

[-389, -11, 0, 2, 13, 32, 142, 3032]

Dart – Sort a List

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 the 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 an integer list then we can use a simple sort function whereas if it is a string list then we use compareTo to sort the list.

There are two main data types which are stored in List:

  • Integer
  • String

We will learn to sort both of them in the article below.

Similar Reads

1. Sorting an Integer List

An integer list can be sorted by the simple sort function....

2. Sorting a String List

The string is sorted by comparing the length in the sort function....

Contact Us