Java - Write code to convert nullable Object To String

Requirements

Write code to convert nullable Object To String

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        Object d = "book2s.com";
        System.out.println(nullObjectToStringEmpty(d));
    }/*from   ww w.  j  a  va  2s  .c  om*/

    public static String nullObjectToStringEmpty(Object d) {
        String dual = "";
        if (d == null) {
            dual = "";
        } else
            dual = d.toString().trim();

        return dual;
    }
}

Related Exercise