Java String Empty emptyStringIfNull(String string)

Here you can find the source of emptyStringIfNull(String string)

Description

Returns an empty string if null.

License

Open Source License

Parameter

Parameter Description
string the string to check.

Declaration

public static final String emptyStringIfNull(String string) 

Method Source Code

//package com.java2s;
/**//from  ww  w.  j a v  a2 s  .co m
 * $RCSFile$
 * $Revision: 18467 $
 * $Date: 2005-02-15 14:36:52 -0800 (Tue, 15 Feb 2005) $
 *
 * Copyright (C) 2004-2008 Jive Software. All rights reserved.
 *
 * This software is published under the terms of the GNU Public License (GPL),
 * a copy of which is included in this distribution, or a commercial license
 * agreement with Jive.
 */

public class Main {
    /**
     * Returns an empty string if null.
     * @param string the string to check.
     */
    public static final String emptyStringIfNull(String string) {
        if (!hasLength(string)) {
            return "";
        }
        return string;
    }

    /**
     * Returns <CODE>true</CODE> if the specified {@link String} is not
     * <CODE>null</CODE> and has a length greater than zero.  This is
     * a very frequently occurring check.
     */
    public static final boolean hasLength(String s) {
        return (s != null && s.length() > 0);
    }
}

Related

  1. emptyString(String s)
  2. emptyString(String str)
  3. emptyString(String str)
  4. emptyString2Null(String stringValue)
  5. emptyStringIfNull(String s)
  6. emptyStrings()
  7. emptyStringToLongZero(String s)
  8. emptyStringToNull(String value)
  9. firstNotEmpty(String... values)