Java - Write code to return default value If a string is Empty

Requirements

Write code to return default value If a string is Empty

Both null and "" are empty string

Hint

Use Conditional operators.

Demo

//package com.book2s;

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

    public static String defaultIfEmpty(String str, String defaultStr) {
        return isEmpty(str) ? defaultStr : str;
    }

    public static boolean isEmpty(String str) {
        return str == null || str.length() == 0;
    }
}