
Java method to determine whether it is a letter:
/**
* 判断是否是字母
* @param str 传入字符串
* @return 是字母返回true,否则返回false
*/
public boolean is_alpha(String str) {
if(str==null) return false;
return str.matches("[a-zA-Z]+");
}Regular expression is a powerful tool for processing strings. It is not a feature of Java. Front-end JavaScript also has . But compared to other old high-level languages, such as C/C, this is where Java is unique than them.
matches() method is used to detect whether a string matches a given regular expression.
Regular expression usage:
1. String matching
2. String search
3. String replacement
For more java knowledge, please pay attention to java basic tutorial.
The above is the detailed content of How to determine whether a string is a letter in java. For more information, please follow other related articles on the PHP Chinese website!