How can I use a method like this
private boolean respectPattern(String password) {
Pattern passwordPattern = Pattern.compile(
"^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[.@$!%*?&])[A-Za-z\\d@$!%*?&.]{8,}$",
Pattern.CASE_INSENSITIVE);
Matcher matcher = passwordPattern.matcher(password);
return matcher.find();
}
If I replace password type with StringBuffer or char[]?
Method
matcher()in classjava util.regex.Patterntakes a single parameter whose type is CharSequence which is an interface. According to the javadoc, there are several implementing classes, includingStringBuffer. If none of the existing implementations are suitable for your needs, you can always write your own implementation.For example, using a CharBuffer