int (CharSequence segment1, CharSequence segment2) { int length1 = segment1.length(); int length2 = segment2.length(); int diff = Integer.compare(length1, length2); for (int i = 0; i < length1 && diff == 0; i++) { diff = segment1.charAt(i) - segment2.charAt(i); } return diff; }