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));
    }/*from   w w  w  .  j av a2  s.com*/

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

Related Exercise