search
HomeJavaJavaBaseJava verifies whether it is a number

Java verifies whether it is a number

Nov 20, 2019 am 10:04 AM
java

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.