Packages
 In this topic

*Constructors

*Methods

 

Packages   PreviousThis PackageNext
Package com.ms.util   Previous This
Package
Next

 


Class StringComparison

public final class StringComparison implements Comparison
{
  // Constructors
  public static final Comparison ascending = new StringComparison(
        1);
  public static final Comparison descending = new StringComparison(
        -1);

  // Methods
  public int compare(Object p, Object q);
}

This class provides a simple comparison, similar to that done by String.compareTo.

For example, given an array of strings like the following:


  String strings[] = new String[4];
  strings[0]="my";
  strings[1]="dog";
  strings[2]="has";
  strings[3]="fleas";

A sort could be performed with the following code:

ArraySort.sort(strings, StringComparison.ascending);

Constructors

StringComparison

public static final Comparison ascending = new StringComparison(1);

Specifies an ascending string comparison. This compares according to String.compareTo.

StringComparison

public static final Comparison descending = new StringComparison(-1);

Specifies a descending string comparison. This compares according to the inverse of String.compareTo.

Methods

compare

public int compare(Object p, Object q);

Compares the two objects.

Return Value:

Returns the result of the comparison.

ParameterDescription
p The first operand of the comparison.
q The second operand of the comparison.

Remarks:

If both objects are instances of the String class, String.compareTo is called. If neither object is a String object, zero is returned. If one of the objects is a String, it is treated as lexicographically preceding the non-String object.

upnrm.gif © 1998 Microsoft Corporation. All rights reserved. Terms of use.