Determining whether the string of numbers (the JAVA)

 

A method, by by Character.isDigit () to determine

 public static void main(String[] args) {
        String content = "123";
        boolean  checkFlag = true;
        for(int i=0;i<content.length();i++){
            if(!Character.isDigit(content.charAt(i))){
                checkFlag = false;
            }
        }
        System.out.println(checkFlag);
    }

 

The second method is determined by the regular expression \ d +

Guess you like

Origin www.cnblogs.com/kiko2014551511/p/11609799.html