Java String Empty to Null emptyToNull(String val)

Here you can find the source of emptyToNull(String val)

Description

empty To Null

License

Open Source License

Declaration

public static String emptyToNull(String val) 

Method Source Code

//package com.java2s;
/**//from w  w w . j a v a2 s.  c  o m
 * Copyright (C) 2006 - present David Bulmore  
 * All Rights Reserved.
 *
 * This file is part of Easy Java Persistence.
 *
 * EJP 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 accompanying license 
 * for more details.
 *
 * You should have received a copy of the license along with EJP; if not, 
 * go to http://www.EasierJava.com and download the latest version.
 */

public class Main {
    public static String emptyToNull(String val) {
        return emptyToDefault(val, null);
    }

    public static String emptyToDefault(String val, String defaultValue) {
        if (val == null || val.length() == 0)
            return defaultValue;

        return val;
    }
}

Related

  1. emptyToNull(String str)
  2. emptyToNull(String str)
  3. emptyToNull(String str)
  4. emptyToNull(String string)
  5. emptyToNull(String text)
  6. emptyToNull(String value)
  7. emptyToString(String str, String returnStr)
  8. isHtmlNull(String str)
  9. nullSafeToString(Object obj)