Im asking me if my code is a common and most efficient way for a custom filter. The user can choose which characters can be used/notUsed. The dirty text can be very long so i have to see that my code needs to be efficient as possible:
String dirtyText = "iamacleantext<>>";
String allowedCharacters = "abcdefhijk$<>/lmnoqrgstuvwxyz";
String result = dirtyText.replaceAll("[" + allowedCharacters + "]","");
if (result.isEmpty()) {
System.out.println("Ok, your text can be used");
} else {
System.out.println("Sorry the text contains not allowed characters");
}
would be thankful for someone who has more knowledge about this