String s = "0392434";
char[] chars = new char[s.length];
s.getChars(0,s.length-1,chars,0);
for(int i = 0; i < chars.length; i++){
if(!Character.isDigit(chars[i]))
return false;
}return true;
char[] chars = new char[s.length];
s.getChars(0,s.length-1,chars,0);
for(int i = 0; i < chars.length; i++){
if(!Character.isDigit(chars[i]))
return false;
}return true;
解决方案 »
- ClassNotFoundException: org.springframework.web.context.ContextLoaderListener异常!
- hibernate中调用Sqlserver的表值函数
- 这些代码怎么组织起来?
- 在线等,关于付款成功,怎么确定去发货
- opencms 自定义结构化类型 乱码
- 可否对某一个class的不同方法做不同的客户端权限分配
- STRUTS 的问题,No action instance for path
- 请问: 在可户端找不到 CMP中定义的 find方法的问题?
- 开会啰开会啰!刘桂香来没来?没来?那就请别的大虾发言吧
- eclipse导入文件后好多错误,求大神帮忙看看
- 到底区别在哪儿?
- 紧急问题!在线等!
用Integer.parseInt(String),或Long.parseLong(String)
如果不抛出异常就说明String是全部是数字的。
String a = "0000000";
boolean alldigit = true;
for (int i = 0; i < a.length(); ++i) {
if (!Character.isDigit(a.charAt(i))) {
alldigit = false;
break;
}
}
boolean b = java.util.regex.Pattern.matches("[0-9]*", a);
System.out.println(b);