ee.String.compareTo Stay organized with collections Save and categorize content based on your preferences.
Page Summary
The
compareTomethod 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.
| Usage | Returns |
|---|---|
String.compareTo(string2) | Integer |
| Argument | Type | Details |
|---|---|---|
this:string1 | String | The string to compare. |
string2 | String | The 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.