Java - How to check for duplicate characters in a string?
I need to write a function that checks a string for duplicate values and returns the count of unique characters. If the count is greater than 3, it should return true. If the count is less than 3, it should be false. Here is what I have been trying (notice I'm new to java) private boolean isFormatValid(String password) { CharSequence inputStr = password; int length = inputStr.length(); int numberDups = 0; for(int i=0; i < length; ++i) { Pattern pattern = Pattern.compile("(.)(?=.*?\1){1,20}"); Matcher matcher = pattern.matcher(inputStr); numberDups += 1; } if (numberDups < 3) { return false; }