static int compareCharIterators(Iterator it1, Iterator it2) { while true { if (!it1.hasNext()) ret it2.hasNext() ? -1 : 0; if (!it2.hasNext()) ret 1; char a = it1.next(), b = it2.next(); if (a < b) ret -1; if (a > b) ret 1; } } static int compareCharIterators(CharacterIterator it1, CharacterIterator it2) { while true { if (!it1.hasNext()) ret it2.hasNext() ? -1 : 0; if (!it2.hasNext()) ret 1; char a = it1.next(), b = it2.next(); if (a < b) ret -1; if (a > b) ret 1; } } static int compareCharIterators(CharacterIterator it1, CharacterIterator it2, CharComparator comparator) { if (comparator == null) ret compareCharIterators(it1, it2); while true { if (!it1.hasNext()) ret it2.hasNext() ? -1 : 0; if (!it2.hasNext()) ret 1; char a = it1.next(), b = it2.next(); int cmp = comparator.compare(a, b); if (cmp != 0) ret cmp; } }