Microsoft SDK for Java

StringSorter.compare

Compares two strings.

Syntax

public static int compare( String s1, String s2 )

public static int compare( String s1, String s2, int options )

public static int compare( Locale locale, String s1, String s2, int options )

Parameters

s1

The first string.

s2

The second string.

locale

A Locale object that represents the locale to be used.

options

The string comparison flags. You can specify any bitwise combination of the following flags:

IGNORECASE   Ignores case.

IGNOREKANATYPE   Does not differentiate between Hiragana and Katakana characters.

IGNORENONSPACE   Ignores nonspacing characters (such as accents, diacritics, and vowel marks).

IGNORESYMBOLS   Ignores symbols.

IGNOREWIDTH   Does not differentiate between single-byte and double-byte characters.

STRINGSORT   All nonalphanumeric characters (including the hyphen and apostrophe) come before alphanumeric characters.

Return Value

Returns -1 if s1 is less than s2, 0 if s1 equals s2, or 1 if s1 is greater than s2.

Remarks

If the two strings are different lengths, they are compared up to the length of the shortest one. If they are equal to that point, the return value indicates that the longer string is greater. Note that if the return value is 0, the two strings are equal in the collation sense, though not necessarily identical.

A null string always sorts before a non-null string. Two null strings are considered equal.

© 1999 Microsoft Corporation. All rights reserved. Terms of use.