Dart - Sort a List Last Updated : 15 Jul, 2025 Comments Improve Suggest changes 10 Likes Like Report 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.Two main data types are stored in List:Integer ListsString ListsWe will learn to sort both of them in the article below. 1. Sorting an Integer ListAn integer list can be sorted by the simple sort function.Example: Dart // Main function void main() { // Creating List List<int> geeksforgeeks = [13, 2, -11, 142, -389, 32, 3032, 0]; // Sorting List geeksforgeeks.sort(); // Printing Sorted List print(geeksforgeeks); } Output:[-389, -11, 0, 2, 13, 32, 142, 3032]2. Sorting a String ListThe string is sorted by comparing the length in the sort function.- Comparing the lengthExample: Dart // Main function void main() { // Creating list of string List<String> geeksforgeeks = ['one', 'two', 'three', 'four']; // Sorting string by comparing the length geeksforgeeks.sort((a, b) => a.length.compareTo(b.length)); // Printing the list print(geeksforgeeks); } Output:[one, two, four, three]If we use sort without comparing the length, then:- Without comparing the lengthExample: Dart // Main function main() { // Creating list of string List<String> geeksforgeeks = ['one', 'two', 'three', 'four']; // Sorting string without // comparing the length geeksforgeeks.sort(); // Printing the list print(geeksforgeeks); } Output:[four, one, three, two]Using the cascades method while sortingExample: Dart // Main function void main() { // Creating list of string List<int> geeksforgeeks = [13, 2, -11, 142, -389, 0]; // Sorting string and Printing the list print(geeksforgeeks..sort()); } Output:[-389, -11, 0, 2, 13, 142] Create Quiz Comment A aditya_taparia Follow 10 Improve A aditya_taparia Follow 10 Improve Article Tags : Dart Dart-List Explore BasicsIntroduction to Dart Programming Language 4 min read Dart SDK Installation 4 min read Dart - Comments 2 min read Dart - Variables 5 min read Operators in Dart 11 min read Dart - Standard Input Output 3 min read Data TypesDart - Data Types 8 min read Basics of Numbers in Dart 6 min read Strings in Dart 6 min read Dart - Sets 6 min read Dart Programming - Map 7 min read Queues in Dart 3 min read Data Enumeration in Dart 3 min read Control FlowDart Programming - If Else Statement (if , if..else, Nested if, if-else-if) 4 min read Switch Case in Dart 2 min read Dart - Loops 4 min read Dart - Loop Control Statements (Break and Continue) 4 min read Labels in Dart 2 min read Key FunctionsDart - Functions 4 min read Different Types of Functions in Dart 4 min read Dart - Anonymous Functions 2 min read Dart - main() Function 2 min read Dart - Common Collection Methods 2 min read How to Exit a Dart Application Unconditionally? 2 min read Dart - Getters and Setters 3 min read Object-Oriented ProgrammingDart - Classes And Objects 4 min read Constructors in Dart 5 min read Super Constructor in Dart 2 min read Dart - this keyword 2 min read Dart - Static Keyword 3 min read Dart - Super and This keyword 4 min read Dart - Concept of Inheritance 5 min read Instance and class methods in Dart 3 min read Method Overriding in Dart 3 min read Getter and Setter Methods in Dart 2 min read Abstract Classes in Dart 4 min read Dart - Builder Class 4 min read Concept of Callable Classes in Dart 4 min read Interface in Dart 3 min read Dart - extends Vs with Vs implements 4 min read Dart UtilitiesDart - Date and Time 3 min read Using await async in Dart 4 min read Dart - Type System 3 min read Generators in Dart 2 min read Dart ProgramsHow to Combine Lists in Dart? 3 min read Dart - Finding Minimum and Maximum Value in a List 5 min read Dart - Splitting of String 1 min read How to Append or Concatenate Strings in Dart? 2 min read How to Find the Length of a String in Dart? 1 min read Dart - Sort a List 2 min read Dart - String toUpperCase() Function with Examples 1 min read Dart - Convert All Characters of a String in Lowercase 1 min read How to Replace a Substring of a String in Dart? 2 min read How to Check String is Empty or Not in Dart (Null Safety)? 1 min read Advance ConceptsException Handling in Dart 3 min read Assert Statements in Dart 3 min read Fallthrough Condition in Dart 3 min read Concept of Isolates in Dart 2 min read Typedef in Dart 3 min read Dart - URIs 2 min read Dart - Collections 7 min read Dart - Basics of Packages 2 min read Dart - String codeUnits Property 1 min read HTML Document Object Model and Dart Programming 3 min read Like