Java - Write code to trim a nullable string with tenary operator

Requirements

Write code to trim a nullable string with tenary operator

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String str = "book2s.com";
        System.out.println(trim(str));
    }// w  w w  . ja v  a  2s .c om

    public static String trim(String str) {
        return str == null ? null : str.trim();
    }
}

Related Exercise