Announcement: All noncommercial projects registered to use Earth Engine beforeApril 15, 2025 mustverify noncommercial eligibility to maintain access. If you have not verified by September 26, 2025, your access may be on hold.

ee.String.compareTo

  • ThecompareTo method lexicographically compares two strings.

  • It returns 0 if the strings are equal, -1 if the first string is less than the second, and 1 if the first string is greater than the second.

  • The method takes one string argument to compare against the invoking string object.

  • Examples are provided for both JavaScript and Python.

Compares two strings lexicographically. Returns: the value 0 if the two strings are lexicographically equal; -1 if string1 is less than string2; and 1 if string1 is lexicographically greater than string2.

UsageReturns
String.compareTo(string2)Integer
ArgumentTypeDetails
this:string1StringThe string to compare.
string2StringThe string to be compared.

Examples

Code Editor (JavaScript)

print(ee.String('a').compareTo('b'));// -1print(ee.String('a').compareTo('a'));// 0print(ee.String('b').compareTo('a'));// 1print(ee.String('a').compareTo(ee.String('b')));// -1

Python setup

See the Python Environment page for information on the Python API and usinggeemap for interactive development.

importeeimportgeemap.coreasgeemap

Colab (Python)

display(ee.String('a').compareTo('b'))# -1display(ee.String('a').compareTo('a'))# 0display(ee.String('b').compareTo('a'))# 1display(ee.String('a').compareTo(ee.String('b')))# -1

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2024-03-19 UTC.