Here you can find the source of trimList(List
public static List<String> trimList(List<String> list)
//package com.java2s; /********************************************************************** * Please see LICENSE.txt/*from ww w . j a va2 s . c om*/ **********************************************************************/ import java.util.List; public class Main { public static List<String> trimList(List<String> list) { if (list != null) { for (int i = 0; i < list.size(); i++) { String val = list.get(i); list.set(i, trimStr(val)); } } return list; } /** * @param input - a String or null * @return -- a trimmed String, with normalized white space */ public static String trimStr(String input) { String retVal = input; if (retVal != null) { retVal = retVal.trim().replaceAll("\\s+", " "); ; } return retVal; } }