public static String normalize ( String text ) { CheckArg . isNotNull ( text , "text" ) ; // This could be much more efficient. return NORMALIZE_PATTERN . matcher ( text ) . replaceAll ( " " ) . trim ( ) ; }
Removes leading and trailing whitespace from the supplied text and reduces other consecutive whitespace characters to a single space . Whitespace includes line - feeds .