int java.lang.String.compareTo(String anotherString)Compares two stringslexicographically(字典序; 按字典顺序;). The comparison is based on theUnicodevalue of each character in the strings. The character sequence represented by this String object is compared lexicographically to the character sequence re...
The equalsIgnoreCase() method of the String class is used to compare two strings lexicographically, ignoring differences in case. It returns true if and only if the argument passed to it is a String object that represents the same sequence of characters as the original string, regardless of diff...
* determined by using the<operator, lexicographically precedes the * other string. In this case, {@code compareTo} returns the * difference of the two character values at position {@code k} in * the two string -- that is, the value: *<blockquote>* this.charAt(k)-anotherString.charAt(...
./ClassCastExceptionExample.java:8: error: incompatible types: Object cannot be converted to String int comparison = ((String) obj2).compareTo(obj1); // ClassCastException occurs here Also Read: Compare two Strings in Java Compare two strings lexicographically in Java Java Integer compareTo() ...
How do you compare two strings in a Java program? JavaStringimplements theComparableinterface, which has two variants of thecompareTo()method. ThecompareTo(String anotherString)method compares theStringobject with theStringargument passed lexicographically. If theStringobject precedes the argument passed...
ThecompareTo()method compares twostringslexicographically (in the dictionary order). The comparison is based on the Unicode value of each character in the strings. Example classMain{publicstaticvoidmain(String[] args){ String str1 ="Learn Java"; ...
compareTo in interface Comparable<String> Parameters: anotherString - the String to be compared. Returns: the value 0 if the argument string is equal to this string; a value less than 0 if this string is lexicographically less than the string argument; and a value greater than 0 if this ...
Returns the number of Unicode code points in the specified text range of this String. CompareTo(String) Compares two strings lexicographically. CompareToIgnoreCase(String) Compares two strings lexicographically, ignoring case differences. Concat(String) Concatenates the specified string to the end of...
Tip: Use the compareToIgnoreCase() method to compare two strings lexicographically, ignoring case differences.Syntaxpublic boolean equalsIgnoreCase(String anotherString) Parameter ValuesParameterDescription anotherString A String, representing the other string to be compared...
int java.lang.String.compareTo(String anotherString) Compares two strings lexicographically(字典序; 按字典顺序;).The comparison is based on the Unicode value of each character in the strings.The character sequence represented by this String object is compared lexicographically to the character ...