Java Null Value Convert convertNull(Object source)

Here you can find the source of convertNull(Object source)

Description

Returns the string representation of a given object or an empty string if the object is null.

License

Open Source License

Parameter

Parameter Description
source - Source object.

Return

String - Formatted string value.

Declaration

public static String convertNull(Object source) 

Method Source Code

//package com.java2s;
/*//  ww  w.ja  va2  s  .com
 * Copyright (C) 2015 Bryan W. Snipes
 * 
 * This file is part of the JDistil web application framework.
 * 
 * JDistil is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * JDistil is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with JDistil.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    /**
      Returns the string representation of a given object or an empty string if
      the object is null.
      @param source - Source object.
      @return String - Formatted string value.
    */
    public static String convertNull(Object source) {
        return convertNull(source, "");
    }

    /**
      Returns the string representation of a given object or a replacement string
      if the object is null.
      @param source - Source object.
      @param replacement - Replacement substring.
      @return String - Formatted string value.
    */
    public static String convertNull(Object source, String replacement) {
        return source == null ? replacement : source.toString();
    }
}

Related

  1. convertNull(Object o)
  2. convertNull2ZeroString(String value)
  3. convertNullableString(Object object)
  4. convertNullString2Empty(Object str)
  5. convertNullToBlank(String s)