Java - Write code to convert nullable Object To Integer

Requirements

Write code to convert nullable Object To Integer

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        Object d = "book2s.com";
        System.out.println(nullObjectToIntegerEmpty(d));
    }/*  ww  w  . j  a  v  a 2s . co m*/

    public static int nullObjectToIntegerEmpty(Object d) {
        int i = 0;
        if (d != null) {
            String dual = d.toString().trim();
            try {
                i = new Integer(dual).intValue();
            } catch (Exception e) {
                System.out.println("Unable to find integer value");
            }
        }
        return i;
    }
}

Related Exercise