Add UnicodeLetterChecker to check if String contains Unicode

This commit is contained in:
anujgaud 2023-10-23 23:44:18 +05:30 committed by GitHub
parent c16eeea003
commit 9756cb1d10
1 changed files with 27 additions and 0 deletions

View File

@ -0,0 +1,27 @@
package com.baeldung.unicode;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.lang3.StringUtils;
public class UnicodeLetterChecker {
public boolean characterClassCheck(String input) {
for (char c : input.toCharArray()) {
if (!Character.isLetter(c)) {
return false;
}
}
return true;
}
public boolean regexCheck(String input) {
Pattern pattern = Pattern.compile("^\\p{L}+$");
Matcher matcher = pattern.matcher(input);
return matcher.matches();
}
public boolean isAlphaCheck(String input) {
return StringUtils.isAlpha(input);
}
public boolean StreamsCheck(String input){
return input.codePoints().allMatch(Character::isLetter);
}
}