Java判断是数字还是字符串

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

方法一:利用正则表达式

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-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实现方...

java.lang.ClassNotFoundException: oracle.jdbc.driver.OralceDriver

 java.lang.ClassNotFoundException: Oracle.jdbc.driver.OracleDriver这个错误;原因可能是 少了驱动 ,少包class...

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

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

程序员为什么不炫富

程序员为什么不炫富

 提到互联网,尤其是互联网工程师们,人们往往会想到两个词:“高薪”和“高压”。在知乎上“为什么很少见工资高的程序员炫富?”的问题下,一个得票很高的答案是:“乐意炫富的人,不是因为有钱,而是因为付出的少...

dwz +jfinal 批量多文件上传 实例

页面部分:<link href="${root}/style/dwz/uploadify/css/uploadify.css" rel="sty...

评论列表

发表评论

访客

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