Write code to return default value If string is Null
//package com.book2s; public class Main { public static void main(String[] argv) { String str = "book2s.com"; System.out.println(defaultIfNull(str)); }//from ww w . j a va 2 s.c o m public static final String EMPTY_STRING = ""; public static String defaultIfNull(String str) { return (str == null) ? EMPTY_STRING : str; } public static String defaultIfNull(String str, String defaultStr) { return (str == null) ? defaultStr : str; } }