Java - Write code to parse Integer from String

Requirements

Write code to parse Integer from String

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String str = "book2s.com";
        System.out.println(getIntegerByStr(str));
    }/*  w w w .j a va2  s  .c o m*/

    public static Integer getIntegerByStr(String str) {
        try {
            Integer temp = Integer.parseInt(str);
            return temp;
        } catch (Exception e) {
            return null;
        }
    }
}