Java - Write code to get empty String If Null using tenary operator

Requirements

Write code to get empty String If Null using tenary operator

Demo

//package com.book2s;

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

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

Related Exercise