java判断字符串是否是整型数字
内容摘要
代码示例:/**
* 判断字符串是否为数字
*/
public static boolean isNumeric(String str){
Pattern pattern = Pattern.compile("[0-9]*");
* 判断字符串是否为数字
*/
public static boolean isNumeric(String str){
Pattern pattern = Pattern.compile("[0-9]*");
文章正文
代码示例:
1 2 3 4 5 6 7 8 | /** * 判断字符串是否为数字 */ public static boolean isNumeric(String str){ Pattern pattern = Pattern.compile( "[0-9]*" ); Matcher isNum = pattern.matcher(str); return isNum.matches(); } |
(免费视频教程推荐:java视频教程)
测试:
1 2 3 4 5 6 | public static void main(String[] args) { String str = "11" ; String str1 = "11sdf" ; System.out.println(isNumeric(str)); System.out.println(isNumeric(str1)); } |
输出结果:
1 2 | true false |
相关文章教程推荐:java入门教程
代码注释
[!--zhushi--]