MCPcopy Create free account
hub / github.com/codenameone/CodenameOne / compareTo

Method compareTo

vm/JavaAPI/src/java/lang/String.java:194–207  ·  view source on GitHub ↗

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 sequence represented by the argument string. The result is a negative integer

(java.lang.String anotherString)

Source from the content-addressed store, hash-verified

192 * this.charAt(k)-anotherString.charAt(k) If there is no index position at which they differ, then the shorter string lexicographically precedes the longer string. In this case, compareTo returns the difference of the lengths of the strings -- that is, the value: this.length()-anotherString.length()
193 */
194 public int compareTo(java.lang.String anotherString){
195 if(anotherString == this) {
196 return 0;
197 }
198 int minL = Math.min(anotherString.length(), length());
199 for(int iter = 0 ; iter < minL ; iter++) {
200 char a = value[offset + iter];
201 char b = anotherString.value[anotherString.offset + iter];
202 if(a != b) {
203 return a - b;
204 }
205 }
206 return length() - anotherString.length();
207 }
208
209 public int compareToIgnoreCase(java.lang.String anotherString) {
210 if (anotherString == this) {

Callers 9

compareMethod · 0.95
evaluateLeftLessRightMethod · 0.95
compareMethod · 0.95
compareVersionsMethod · 0.95
compareVersionsMethod · 0.95
stableStringSortMethod · 0.95

Calls 3

minMethod · 0.95
lengthMethod · 0.95
lengthMethod · 0.65

Tested by

no test coverage detected