当前位置:学者斋 >

计算机 >java语言 >

java判断字符串是否为数字的几个方法

java判断字符串是否为数字的几个方法

本文实例总结了JAVA判断字符串是否为数字的方法。

java判断字符串是否为数字的几个方法

方法一:用JAVA自带的函数

public static boolean isNumeric(String str){ for (int i = th();--i>=0;){ if (!git(At(i))){ return false; } } return true;}

方法二:用正则表达式

public static boolean isNumeric(String str){ Pattern pattern = ile("[0-9]*"); return her(str)hes(); }

方法三:用ascii码

public static boolean isNumeric(String str){ for(int i=th();--i>=0;){ int chr=At(i); if(chr<48 chr="">57) return false; } return true;}

希望本文所述对大家Java程序设计有所帮助。

标签: JAVA 字符串
  • 文章版权属于文章作者所有,转载请注明 https://xuezhezhai.com/jsj/java/wlowog.html