HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
String Methods : Compare two strings
The compareTo()
method compares two strings
lexicographically.
The comparison is based on the Unicode value of each character in the strings.
The method returns 0 if the string is equal to the other string. A value less than 0 is returned if the string is less than the other string (less characters) and a value greater than 0 if the string is greater than the other string (more characters).
public int compareTo(String string2)
public int compareTo(Object object)
Parameter | Description |
---|---|
string2 | A String , representing the other string to be compared |
object | An Object , representing an object to be compared |
Returns: | An int value: 0 if the string is equal to the other string.< 0 if the string is lexicographically less than the other string > 0 if the string is lexicographically greater than the other string (more characters) |
---|
❮ String Methods