Java判断字符串是否以数字开头

绝地灬酷狼 2022-06-09 03:46 788阅读 0赞

使用正则表达式

  1. //判断字符串是不是以数字开头
  2. public static boolean isStartWithNumber(String str) {
  3. Pattern pattern = Pattern.compile("[0-9]*");
  4. Matcher isNum = pattern.matcher(str.charAt(0)+"");
  5. if (!isNum.matches()) {
  6. return false;
  7. }
  8. return true;
  9. }

发表评论

表情:
评论列表 (有 0 条评论,788人围观)

还没有评论,来说两句吧...

相关阅读