public static String trimAndConvertEmptyToNull(String str){
  if (str == null) {
    return null;
  }
  String newStr=str.trim();
  if (newStr.length() < 1) {
    return null;
  }
  return newStr;
}

public static String trimAndConvertEmptyToNull ( String str ) { if ( str == null ) { return null ; } String newStr = str . trim ( ) ; if ( newStr . length ( ) < 1 ) { return null ; } return newStr ; }
trims passed string and converts it to null if the resulting string has length zero .
