Locale-Sensitive Java Method
public int compareTo(String anotherString)
Internationalization (I18n) Method Overview
This method compares two strings based on the UTF-16 Unicode
numeric code points of each character in the strings. The result is a negative integer
if this String object lexicographically precedes the argument string.
The result is a positive integer if this String object lexicographically follows the argument string.
The result is zero if the strings are equal;
compareTo returns 0 exactly when the
equals(Object) method would return true.
When this method is being used to compare two strings for the purpose of
collation (alphabetic sorting), it should be replaced with the appropriate call to the
java.text.Collator class to
take advantage of locale-based character sorting.
Globalyzer will not be able to determine whether you are calling this method
for purposes of determining equality or to perform locale-sensitive character
collation. In cases
where it is called to determine String equality and hence you know that
the call does
not pose an I18n problem, you can use Globalyzer's
functionality to ensure that it isn't picked up again in a subsequent scan.
public int compare(Object o1,
int i = stringA.compareTo(stringB);
//retrieve the runtime user's locale
Locale locale = new Locale(getUserLocale());
//pass the user's locale as an argument
Collator myCollator = Collator.getInstance(locale);
int i = myCollator.compare(stringA,stringB);
for more information.
Locale-Sensitive Java Methods