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...
1 /* @param anotherString the String to be compared. 2 * @return the value 0 if the argument string is equal to 3 * this string; a value less than 0 if this string 4 * is lexicographically less than the string argument; and a 5 * value greater than 0 if this string is 6 * l...
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"; String str2 ="Learn Kolin";intresult;// compar...
If there is no index position at which they differ, then the shorter string lexicographically precedes the longer string. In this case,compareToreturns the difference of the lengths of the strings -- that is, the value: this.length()-anotherString.length() 1.当字符串s1和s都表示数字时,有三...
一.首先先来看下java.lang.String这个类下面的equals方法是如何实现的。 AI检测代码解析 public boolean equals(Object anObject) { if (this == anObject) { //判断对象的地址是否一致 return true; } if (anObject instanceof String) { //判断anObject是否是String类型 ...
Return Value : The value 0 if the argument is a string lexicographically equal to this string; a value less than 0 if the argument is a string lexicographically greater than this string; and a value greater than 0 if the argument is a string lexicographically less than this string./...
UsingcompareTo()method (comparing strings lexicographically) 1. Compare strings usingequals()method In this way, I am using.equals()instance method of the String class. Originally.equals()method is theObjectclass method, String class overrides it. ...
ExampleGet your own Java Server Compare two strings: StringmyStr1="Hello";StringmyStr2="Hello";System.out.println(myStr1.compareTo(myStr2));// Returns 0 because they are equal Try it Yourself » Definition and Usage ThecompareTo()method compares two strings lexicographically. ...
anotherString String the String to be compared.ReturnsInt32 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 string is lexicographically greater than the ...
Java String compareTo() Method: The compareTo() method compares two strings lexicographically. The comparison is based on the Unicode value of each character in the strings.