Last active
November 10, 2015 13:25
-
-
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"));
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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