Skip to content

Instantly share code, notes, and snippets.

@lovasoa
Created October 23, 2018 09:05
Show Gist options
  • Save lovasoa/65460dc69073e3cce56e2aa2ac40d768 to your computer and use it in GitHub Desktop.
Save lovasoa/65460dc69073e3cce56e2aa2ac40d768 to your computer and use it in GitHub Desktop.
private static PrimitiveIterator.OfInt alphaChars(CharSequence s) {
return s.chars().filter(Character::isAlphabetic).map(Character::toLowerCase).iterator();
}
public static boolean compareAlphabeticCharacters(CharSequence a, CharSequence b) {
PrimitiveIterator.OfInt aStream = alphaChars(a);
PrimitiveIterator.OfInt bStream = alphaChars(b);
while (aStream.hasNext() && bStream.hasNext()) {
if (aStream.nextInt() != bStream.nextInt()) return false;
}
return !aStream.hasNext() && !bStream.hasNext();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment