Java examples for java.lang:String Null Or Empty
Return empty String for null string
public class Main { public static void main(String[] argv) { String s = "java2s.com"; System.out.println(getString(s)); /* w w w . j a va2 s. co m*/ s = null; System.out.println(getString(s)); } public static String getString(String s) { return s == null ? "" : s; } }