compareTo method

int? compareTo(
  1. String other
)

Compares this string to other.

Returns a negative value if this is ordered before other, a positive value if this is ordered after other, or zero if this and other are equivalent.

The ordering is the same as the ordering of the code units at the first position where the two strings differ. If one string is a prefix of the other, then the shorter string is ordered before the longer string. If the strings have exactly the same content, they are equivalent with regard to the ordering. Ordering does not check for Unicode equivalence. The comparison is case sensitive.

var relation = 'Dart'.compareTo('Go');
print(relation); // < 0
relation = 'Go'.compareTo('Forward');
print(relation); // > 0
relation = 'Forward'.compareTo('Forward');
print(relation); // 0

Implementation

int? compareTo(String other) => value?.compareTo(other);