Newer Version Available

This content describes an older version of this product. View Latest

Collator Class

Contains methods to get locale-specific instances that can be used for comparisons and sorting. Use the getInstance() method to obtain the Collator instance for a given locale and pass the Collator as the Comparator parameter to the list.sort() method.

Namespace

System

Usage

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.

Example

This example performs a default list sort and then uses Collator to sort based on the user locale.

Collator Methods

The following are methods for Collator.

compare(source, target)

Perform string comparisons for a given locale.

Signature

public Integer compare(String source, String target)

Parameters

source
Type: String
target
Type: String

Return Value

Type: Integer

getInstance()

Gets the Collator instance for the current user’s locale.

Signature

public static System.Collator getInstance()

Return Value

Type: Collator Class