Skip to content

Instantly share code, notes, and snippets.

@billmote
Last active November 10, 2015 13:25
Show Gist options
  • Save billmote/d230e709bf15a64a21b4 to your computer and use it in GitHub Desktop.
Save billmote/d230e709bf15a64a21b4 to your computer and use it in GitHub Desktop.
"Write a method that determines whether all the characters in a string are the same, using only library string methods, but no loops or recursion." Tests ... assertEquals(true, allDuplicateChars("cccccc")); assertEquals(false, allDuplicateChars("abcdef"));
public class DupeChecker {
public boolean allDuplicateChars(final String input) {
if (input == null || input.length() == 0) {
return false;
}
String firstChar = input.substring(0,1);
String matchingChars[] = input.split(firstChar + "+");
return matchingChars.length == 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment