Java - Write code to check if a string is representing an Integer value

Requirements

Write code to check if a string is representing an Integer value

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String src = "book2s.com";
        System.out.println(isInteger(src));
    }//from   w w w . j a  va2s  .  c  o  m

    public static boolean isInteger(String src) {
        if (src == null || src.equals(""))
            return false;
        try {
            Integer.parseInt(src);
            return true;
        } catch (Exception e) {
            return false;
        }
    }
}

Related Exercise