java中判断字符串是否为纯数字
2015-12-10 10:04
399 查看
java中判断字符串是否为纯数字
方法一:利用正则表达式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();
if (result == true) {
System.out.println("该字符串是纯数字");
}else{
System.out.println("该字符串不是纯数字");
}
}
}
相关文章推荐
- 【Java EE (Struts2 + Spring + Hibernate)开发】:Hibernate(一)基本用法
- JAVA常用框架和插件
- java web项目答辩答辩题总结(书本网上语言答辩+自己的语言答辩)
- Spring整合SpringMVC
- MyEclipse工程高版本换低版本报错
- Spring+Struts2
- java web项目中的拦截未登录用户的问题
- java代码分析及分析工具
- 【Java并发编程实战】-----“J.U.C”:CLH队列锁
- java中包命名常见规则
- myeclipse 使用 color theme javascirpt背景发白
- java客户端调用Servlet
- Java中equals和==的区别
- 【Java并发编程实战】-----“J.U.C”:CLH队列锁
- org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document fro
- Java设计模式——工厂模式
- Java设计模式——工厂模式
- MyEclipse、Eclipse自动提示不起作用
- 从头认识java-13.1 泛型与容器(容器的演变)
- Spring:AOP编程