Java - Write code to return default If string Empty

Requirements

Write code to return default If string Empty

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String str = "book2s.com";
        System.out.println(defaultIfEmpty(str));
    }//  www.j a v a 2  s .  c o  m

    public static final String EMPTY_STRING = "";

    public static String defaultIfEmpty(String str) {
        return (str == null) ? EMPTY_STRING : str;
    }

    public static String defaultIfEmpty(String str, String defaultStr) {
        return ((str == null) || (str.length() == 0)) ? defaultStr : str;
    }
}