Java判断是数字还是字符串

1549年前 (2017-03-06)java技术4164

方法一:利用正则表达式

public class Testone {
public static void main(String[] args){
String str="123456";
boolean result=str.matches("[0-9]+");
if (result == true) {
System.out.println("该字符串是纯数字");}else{System.out.println("该字符串不是纯数字");}}}

方法二:利用Pattern.

import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Testone {
public static void main(String[] args){
String str="123456";
Pattern pattern = Pattern.compile("[0-9]{1,}");
Matcher matcher = pattern.matcher((CharSequence)str);
boolean result=matcher.matches();
System.out.println("该字符串是纯数字");}else{System.out.println("该字符串不是纯数字");}}}


本文原创,转载必追究版权。

分享给朋友:

相关文章

org.tigris.subversion.javahl.ClientException:Attempted to lock an already-lo

 svn更新或提交是报错:org.tigris.subversion.javahl.ClientException:Attempted to lock an already-locked d...

多说评论框怎么用更好

 1.隐藏屏蔽掉多说评论框的版权链接代码?简单css实现:多说隐藏版权链接,在后台自定义css添加:#ds-thread #ds-reset .ds-powered-by { display...

plsql 中number类型字段 取消科学计数法显示

 PL/SQL DEVELOPER中禁用科学计数法:Tools - Prefrence - SQL Window - 选择:"Number fields to_char&quo...

jquery 操作html元素(及CSS)

jquery 操作html元素(及CSS)

 $("li").addClass("aui-user-view-cell aui-img") ;  //给元素添加样式$('#a1...

jfinal 定时任务

1、去quartz官网下载 定时任务jar包(http://www.quartz-scheduler.org/)quartz-*.*.*.jar2、创建定时任务:public class SetAre...

Jfinal+Jquery uploadify实现多文件上传实例

Jfinal+Jquery uploadify实现多文件上传实例

包文件外部jar包jfinal-2.0-bin-with-src.jar(JFinal核心包)  fastjson-1.2.7.jar(用于json数据的处理)  cos-26De...

评论列表

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。