Java判断是数字还是字符串

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

方法一:利用正则表达式

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("该字符串不是纯数字");}}}


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

分享给朋友:

相关文章

高情商女孩,女生看了都喜欢

高情商女孩,女生看了都喜欢

 王晨阳:19岁大四,北京航空航天大学,插画专业,夜市卖过化妆品,开过儿童美术教学班,某网站签约网络小说作家,15岁开始,3年时间写了8部小数约24万字;对话1:沈东军 vs王晨阳沈东军:像...

showModalDialog取得父窗口的方法

 通常使用window.open的方式开启新窗口的话要取得父窗口的控件,可以用window.opener来取得父窗口然而如果使用showModalDialog的话...却无效如果有需要的话,...

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

 svn更新或提交时候报错:org.tigris.subversion.javahl.ClientException:Attempted to lock an already-locke...

如何彻底卸载删除oracle数据库

 windows下如何彻底删除Oracle 软件环境: 1、Windows 2000+ORACLE 8.1.7 ,oracle 10g2、ORACLE安装路径为:C:\ORACLE实现方...

使用Myeclipse 8.5开发基于JAX-WS的Web service实例

 本文为Web service 开发入门篇,主要介绍在Myeclipse 8.5环境下开发Web service的服务程序和客户端程序的基本流程。 在Weblogic 11g...

freeMarker 截取字符串(操作字符串函数 )

<#if c.proSummary!?length gt 25>  <!-- 如果长度 >25 截取25个字-->    ...

评论列表

发表评论

访客

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