Java - Write code to return default String if the string parameter is empty

Requirements

Write code to return default String if the string parameter is empty

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String str = "book2s.com";
        System.out.println(defaultString(str));
    }/*ww w.jav  a2  s .  c  o m*/

    public static String defaultString(String str) {
        return str != null ? str : "";
    }

    public static String defaultString(String str, String defaultStr) {
        return str != null ? str : defaultStr;
    }
}