import org.apache.commons.lang.StringUtils; String str = " Hello World! "; String trimmedStr = StringUtils.trim(str); System.out.println(trimmedStr); // Output: "Hello World!"
import org.apache.commons.lang.StringUtils; String[] arr = {" apple ", "banana ", " cherry "}; String[] trimmedArr = StringUtils.trim(arr); for(String s : trimmedArr) { System.out.println(s); } // Output: "apple", "banana", "cherry"
import org.apache.commons.lang.StringUtils; String str = null; String trimmedStr = StringUtils.trim(str); if(StringUtils.isEmpty(trimmedStr)) { System.out.println("Input string is null or empty"); } // Output: "Input string is null or empty"To use StringUtils in your Java project, you need to include the Apache Commons Lang library in your classpath. The package name for StringUtils is `org.apache.commons.lang`.