Home  >  Article  >  Java  >  How to determine whether a string is a letter in java

How to determine whether a string is a letter in java

尚
Original
2019-11-22 09:17:488698browse

How to determine whether a string is a letter in java

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn