Java - Write code to return default value for null String using if statement

Requirements

Write code to return default value for null String using if statement

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String value = null;/* w  ww. j  a v  a  2 s . co  m*/
        String null_str = "book2s.com";
        System.out.println(getString(value, null_str));
    }

    public static String getString(String value, String null_str) {
        if (value == null)
            return null_str;
        return value.trim();
    }
}

Related Exercise