Java tutorial
//package com.java2s; public class Main { /** * Returns null if the given string is not null and contains no characters, * the string itself otherwise. * * @param string the string. * @return null if the given string is not null and contains no characters, * the string itself otherwise. */ public static String nullIfEmpty(String string) { return string != null && string.trim().length() == 0 ? null : string; } }