How do I find out if first character of a string is a number?

前端 未结 6 1176
暖寄归人
暖寄归人 2020-11-29 18:13

In Java is there a way to find out if first character of a string is a number?

One way is

string.startsWith(\"1\")

and do the abov

6条回答
  •  难免孤独
    2020-11-29 19:02

    regular expression starts with number->'^[0-9]' 
    Pattern pattern = Pattern.compile('^[0-9]');
     Matcher matcher = pattern.matcher(String);
    
    if(matcher.find()){
    
    System.out.println("true");
    }
    

提交回复
热议问题