Java String Empty to Null emptyStringToNull(String str)

Here you can find the source of emptyStringToNull(String str)

Description

empty String To Null

License

Creative Commons License

Declaration

public static String emptyStringToNull(String str) 

Method Source Code

//package com.java2s;
/*//  w  w  w  . ja va  2s  .  com
 * Dotcms minifier by ISAAC is licensed under a 
 * Creative Commons Attribution 3.0 Unported License
 * 
 * - http://creativecommons.org/licenses/by/3.0/
 * - http://www.geekyplugins.com/
 * 
 * ISAAC Software Solutions B.V. (http://www.isaac.nl)
 */

public class Main {
    public static String emptyStringToNull(String str) {
        return str == null || str.equals("") ? null : str;
    }

    public static String emptyStringToNull(String str, String ifNullValue) {
        String ret = str == null || str.equals("") ? null : str;
        return ret == null ? ifNullValue : ret;
    }
}

Related

  1. emptyStringToNull(String input)
  2. emptyStringToNull(String string)
  3. emptyToDefault(String value, String def)
  4. emptyToDefault(T[] values, T[] def)
  5. emptyToNull(final String text, final boolean doTrim)