Return default String for empty string - Android java.lang

Android examples for java.lang:String Null or Empty

Description

Return default String for empty string

Demo Code

public class Main{
    public static final String EMPTY = "";
    public static String defaultString(String string) {
        return defaultString(string, EMPTY);
    }//from   w w w  .  j a v  a2  s  .  c o  m
    public static String defaultString(String string, String defaultString) {
        if (string == null) {
            return defaultString;
        }

        return string;
    }

}

Related Tutorials