What is a good alternative of LTRIM and RTRIM in Java?
With a regex you could write: String s = … String ltrim = s.replaceAll(“^\\s+”,””); String rtrim = s.replaceAll(“\\s+$”,””); If you have to do it often, you can create and compile a pattern for better performance: private final static Pattern LTRIM = Pattern.compile(“^\\s+”); public static String ltrim(String s) { return LTRIM.matcher(s).replaceAll(“”); } From a performance perspective, … Read more