is String an Int number - Android java.lang

Android examples for java.lang:String Parse

Description

is String an Int number

Demo Code


//package com.java2s;

public class Main {
    static public boolean isInt(String text) {
        if (text != null && text.length() > 0) {

            if (!isNumeric(text.charAt(0)) && text.charAt(0) != '-'
                    && text.charAt(0) != '-')
                return false;

            for (int i = 1; i < text.length(); ++i)
                if (!isNumeric(text.charAt(i)))
                    return false;

            return true;

        }/* www .  j  av a2s  .  c o m*/
        return false;
    }

    static public boolean isNumeric(char c) {
        return c >= '0' && c <= '9';
    }
}

Related Tutorials