JAVA Method: boolean isInteger()

5Feb09

Hoy tenía la necesidad de ver si un texto es un entero o no. He estado buscando un buen rato en google hasta que he dado con ella. Aquí os la dejo:

private static boolean isDouble(String str) {
        try {
                double v = Double.parseDouble(str);
                return true;
        } catch(NumberFormatException e) {
                return false;
        }
}
 
private static boolean isInteger(String str) {
        try {
                int v = Integer.parseInt(str);
                return true;
        } catch(NumberFormatException e) {
                return false;
        }
}

It works! :)

No comments yet.

Write a comment: