Java - Write code to return default value If string is Null

Requirements

Write code to return default value If string is Null

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String str = "book2s.com";
        System.out.println(defaultIfNull(str));
    }/*from   www  .  java2  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;
    }
}