Java String Value Of valueOfOrEmptyString(final Object object)

Here you can find the source of valueOfOrEmptyString(final Object object)

Description

Returns with an empty string is the argument is null otherwise returns with String#valueOf(Object) .

License

Apache License

Parameter

Parameter Description
object an object.

Return

empty string is the object is null otherwise with the of the argument.

Declaration

public static String valueOfOrEmptyString(final Object object) 

Method Source Code

//package com.java2s;
/*// w ww  . ja v  a  2  s.c om
 * Copyright 2011-2015 B2i Healthcare Pte Ltd, http://b2i.sg
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class Main {
    /**Shared empty string.*/
    public static final String EMPTY_STRING = "";

    /**
     * Returns with an empty string is the argument is {@code null} otherwise 
     * returns with {@link String#valueOf(Object)}.
     * @param object an object.
     * @return empty string is the object is {@code null} otherwise with the 
     * {@link Object#toString()} of the argument.
     */
    public static String valueOfOrEmptyString(final Object object) {
        return null == object ? EMPTY_STRING : String.valueOf(object);
    }
}

Related

  1. valueOfIgnoreCase(Class enumType, String constantName)
  2. valueOfInteger(final String s, int radix)
  3. valueOfIpv4(String ip)
  4. valueOfLongToString(long[] values)
  5. valueOfNullSafe(final Class enumType, final String name)
  6. valueOfString(String str, int len)
  7. ValueOfString(String value)
  8. valueOfStringToLong(String[] values)
  9. valueOfYesNo(String parameter)