–public
int compareTo(String anotherString)
– {
– int len1 = this.count; // a field
– int len2 = anotherString.count;
– int n = Math.min(len1, len2);
– char v1[] = this.value; // another field
– char v2[] = anotherString.value;
– int i = offset; // pretend
offset=0
– int j = anotherString.offset;
– while (n-- != 0) { // code like C
– char c1 = v1[i++]; // i++ in loop
– char c2 = v2[j++];
– if (c1 != c2) { // (first) mismatch
– return c1 - c2; // subtract ints
– }
– }
– return len1 - len2; // same length?
– }
•