Java tutorial
//package com.java2s; // From org.springframework.util.StringUtils, under Apache License 2.0 public class Main { /** * <p>Removes control characters (char <= 32) from both * ends of this String, handling {@code null} by returning * {@code null}.</p> * <p> * <p>The String is trimmed using {@link String#trim()}. * Trim removes start and end characters <= 32. * <p> * <p>To trim your choice of characters, use the * <p> * <pre> * StringUtils.trim(null) = null * StringUtils.trim("") = "" * StringUtils.trim(" ") = "" * StringUtils.trim("abc") = "abc" * StringUtils.trim(" abc ") = "abc" * </pre> * * @param str the String to be trimmed, may be null * @return the trimmed string, {@code null} if null String input */ public static String trim(final String str) { return str == null ? null : str.trim(); } }