Java - Write code to create a function to convert object to String and handle null value

Requirements

Write code to create a function to convert object to String and handle null value

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        Object object = "book2s.com";
        System.out.println(toString(object));
    }//from w  w w.  j ava  2  s . c  o  m

    public static String toString(Object object) {
        return object == null ? "(null)" : object.toString();
    }
}

Related Exercise