網路城邦
上一篇 回創作列表 下一篇   字體:
判斷String中是否皆為數字
2011/12/01 11:46:53瀏覽957|回應0|推薦0

方式一 :
  String str = "12354";
  System.out.println("str = " + str);
  System.out.println("判斷str是否為數字  = " + str.matches("[0-9]+"));

 

-----------------------------------------------------------------------------------------------

方式二 :
String   a   =  "12345";
Pattern   regex   =   Pattern.compile( "[0-9]* ");
Matcher   match   =   regex.matcher(a);
boolean   flag   =   match.matches();

( 休閒生活網路生活 )
回應 推薦文章 列印 加入我的文摘
上一篇 回創作列表 下一篇

引用
引用網址:https://classic-blog.udn.com/article/trackback.jsp?uid=ulinaboy&aid=5888694