public static String trim(CharSequence s){
  if (s == null) {
    return null;
  }
  Matcher m=sTrimPattern.matcher(s);
  return m.replaceAll("$1");
}

public static String trim ( CharSequence s ) { if ( s == null ) { return null ; } Matcher m = sTrimPattern . matcher ( s ) ; return m . replaceAll ( "$1" ) ; }
trims the string , removing all whitespace at the beginning and end of the string . non - breaking whitespaces are also removed .
