判断字符串中是否为数字的三种方法
生活随笔
收集整理的這篇文章主要介紹了
判断字符串中是否为数字的三种方法
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
//1用JAVA自帶的函數(shù)
public static boolean isNumeric(String str){for (int i = str.length();--i>=0;){ if (!Character.isDigit(str.charAt(i))){return false;}}return true;}//2用正則表達(dá)式
public static boolean isNumeric(String str){ Pattern pattern = Pattern.compile("[0-9]*"); return pattern.matcher(str).matches(); } //3用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;
}
?
轉(zhuǎn)載于:https://www.cnblogs.com/liaoliao/p/5052954.html
總結(jié)
以上是生活随笔為你收集整理的判断字符串中是否为数字的三种方法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 交通银行信用卡制卡要多久能到?申卡到收卡
- 下一篇: 光大凯撒旅游白金卡手续费如何收取?费用信