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));
    }//  w w w .j  ava 2 s.c o m

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