Home  >  Article  >  Java  >  How to determine whether a character is a number in java

How to determine whether a character is a number in java

王林
王林Original
2019-11-23 11:15:512923browse

How to determine whether a character is a number in java

In C, you can use isdigit() to determine whether a character is a number, and isalpha() to determine whether a character is a letter. Similar methods in JAVA are mainly It is a static method of the Character class:

The example is as follows:

Character.isDigit( char ch )   // 判断ch是否是数字字符,如'1','2‘,是返回true。
否则返回false
Character.isLowerCase(c) || Character.isUpperCase(c) // 判断ch是否是字母字符,如'a','b‘,是返回true。
否则返回false
Character.isLetterOrDigit( char ch ) // 判断ch是否是字母或数字字符,如'a','b‘,'1','2',是返回true。
否则返回false

Recommended tutorial: java introductory tutorial

The above is the detailed content of How to determine whether a character is a number 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