Write code to Check if the supplied value is an integer - Java java.lang

Java examples for java.lang:int Parse

Requirements

Write code to Check if the supplied value is an integer

Demo Code

//package com.java2s;

public class Main {
    public static void main(String[] argv) {
        String value = "java2s.com";
        System.out.println(isInteger(value));
    }/* w w  w . j  ava  2s  .c om*/

    /**
     * Checks if the supplied value is an integer
     * @param value String to be checked
     * @return true if the value is an integer, false otherwise
     */

    public static boolean isInteger(String value) {
        try {
            Integer.valueOf(value);
        } catch (NumberFormatException e) {
            return false;
        }
        return true;
    }
}

Related Tutorials