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

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

        return dual;
    }
}

Related Exercise