is string all Numeric character - Android java.lang

Android examples for java.lang:Character

Description

is string all Numeric character

Demo Code

import android.text.TextUtils;
import android.util.Patterns;
import java.util.regex.Pattern;

public class Main{

    public static boolean isNumeric(String string) {
        if (string == null) {
            throw new NullPointerException("The string must not be null!");
        }/*w ww . ja  v a2  s. c  o  m*/
        final int length = string.length();
        if (length == 0) {
            return false;
        }
        for (int i = 0; i < length; ++i) {
            if (!Character.isDigit(string.charAt(i))) {
                return false;
            }
        }
        return true;
    }

}

Related Tutorials