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));
    }//  www .ja  v a 2s  .co 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;
        }
    }
}