位置: 首頁 > 計算機 > java語言

java判斷字串是否為數字的幾個方法

2016-10-23 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 字串
2017-02-20
2014-11-17
2014-11-22
2017-02-20
2016-10-23
2016-06-12
2016-04-10
2015-09-20
2016-10-23
2014-11-18

Copyright ©2024 才華齋 All Rights Reserved.