---
schema_version: "1"
id: ac34de45e2b5f4325aef3013f40010ca037fff3842a439fb241513a27eefb1ee
title: Lists of Custom Types and Sorting
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexcode/apex_classes_list_sorting.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_list_sorting.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: e984a4ad9e07d02d3d2744aa76aa880e4ebe1a712d0d3d6c6c7be27fa185f31d
description: Lists can hold objects of your user-defined types (your Apex classes). Lists of user-defined types can be sorted.
---
# Lists of Custom Types and Sorting

Lists can hold objects of your user-defined types (your Apex classes). Lists of user-defined types can be sorted.

To sort such a list, your Apex class can implement the Comparator interface and pass it as a parameter to the List.sort method. Alternatively, your Apex class can implement the Comparable interface.

The sort criteria and sort order depend on the implementation that you provide for the Comparable.compareTo or the Comparator.compare method.

To perform locale-sensitive comparisons and sorting, use the Collator class. Because locale-sensitive sorting can produce different results depending on the user running the code, avoid using it in triggers or in code that expects a particular sort order.

- [← Previous](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_version_settings_intro.htm "Apex Code Versions")
- [Next →](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_collections_maps_keys_userdefined.htm "Using Custom Types in Map Keys and Sets")

#### See Also

- [_Apex Reference Guide_: Collator Class](https://developer.salesforce.com/docs/atlas.en-us.264.0.apexref.meta/apexref/apex_class_System_Collator.htm)
- [_Apex Reference Guide_: Comparable Interface](https://developer.salesforce.com/docs/atlas.en-us.264.0.apexref.meta/apexref/apex_comparable.htm)
- [_Apex Reference Guide_: Comparator Interface](https://developer.salesforce.com/docs/atlas.en-us.264.0.apexref.meta/apexref/apex_interface_System_Comparator.htm)