Home  >  Article  >  Java  >  Java verifies whether it is a number

Java verifies whether it is a number

尚
Original
2019-11-20 10:04:472252browse

Java verifies whether it is a number

java determines whether it is a number:

int id = 12345689797;
Pattern pattern = Pattern.compile("[0-9]*");
Matcher isNum = pattern.matcher(id);
if( !isNum.matches() ){
  //不是数字
}else{
  //是数字
}

matches() method is used to detect whether a string matches a given regular expression.

Syntax

public boolean matches(String regex)

Parameters

regex -- Regular expression that matches strings.

Return value

Returns true when the string matches the given regular expression.

For more java knowledge, please pay attention to java basic tutorial.

The above is the detailed content of Java verifies whether it is a number. 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