Java Null Value Convert null2String(Object obj)

Here you can find the source of null2String(Object obj)

Description

Converts null to empty string, otherwise returns it directly.

License

Open Source License

Parameter

Parameter Description
string The nullable string

Return

empty string if passed in string is null, or original string without any change

Declaration

public static String null2String(Object obj) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from  w  w  w  .j  av  a 2 s. c o  m
     * Converts <code>null</code> to empty string, otherwise returns it
     * directly.
     * 
     * @param string
     *            The nullable string
     * @return empty string if passed in string is null, or original string
     *         without any change
     */
    public static String null2String(Object obj) {
        return obj == null ? "" : obj.toString();
    }

    public static String null2String(String str) {
        return str == null ? "" : str;
    }
}

Related

  1. null2Length0(String s)
  2. null2NA(String str)
  3. Null2Space(String str)
  4. null2Str(Object obj)
  5. null2Str(String str)
  6. null2String(String str)
  7. null2String(String string)
  8. null2void(String str)