Java判断是数字还是字符串

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

方法一:利用正则表达式

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


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

分享给朋友:

相关文章

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

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

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

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

get方式调用http接口   Header赋参数值

get方式调用http接口 Header赋参数值

   /**      195.     * 发送...

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

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

freemarker 判断日期变量为空处理 及InvalidReferenceException异常处理

at freemarker.core.InvalidReferenceException.getInstance(InvalidReferenceException.java:98);InvalidR...

MyEclipse 10 性能大优化

MyEclipse 10 性能大优化

 MyEclipse 10已发布,新版本的特性能够大大提高开发者的效率。但同时,由于电脑配置的原因,很多开发者在使用MyEclipse的时候,速度都不是很快,需要我们对MyEclipse进行...

评论列表

发表评论

访客

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