zl程序教程

您现在的位置是:首页 >  后端

当前栏目

Java:判断字符串是否为数字的五种方法详解编程语言

JAVA方法编程语言 详解 字符串 判断 数字 是否
2023-06-13 09:11:43 时间
public static boolean isInteger(String str) { Pattern pattern = Pattern.compile("^[-//+]?[//d]*$"); return pattern.matcher(str).matches(); //方法三: public static boolean isNumeric(String str){ Pattern pattern = Pattern.compile("[0-9]*"); return pattern.matcher(str).matches(); //方法四: public final static boolean isNumeric(String s) { if (s != null !"".equals(s.trim())) return s.matches("^[0-9]*$"); else return false; //方法五:用ascii码 public static boolean isNumeric(String str){ for(int i=str.length();--i =0;){ int chr=str.charAt(i); if(chr 48 || chr 57) return false; return true; }

 

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/16761.html

cjava