代码示例:
/** * 判断字符串是否为数字 */ public static boolean isNumeric(String str){ Pattern pattern = Pattern.compile("[0-9]*"); Matcher isNum = pattern.matcher(str); return isNum.matches(); }
(免费视频教程推荐:java视频教程)
测试:
public static void main(String[] args) { String str = "11"; String str1 = "11sdf"; System.out.println(isNumeric(str)); System.out.println(isNumeric(str1)); }
输出结果:
true false
相关文章教程推荐:java入门教程
立即学习“Java免费学习笔记(深入)”;
以上就是java判断字符串是否是整型数字的详细内容,更多请关注php中文网其它相关文章!
java怎么学习?java怎么入门?java在哪学?java怎么学才快?不用担心,这里为大家提供了java速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号