Here you can find the source of trimElements(List
public static List<String> trimElements(List<String> list)
//package com.java2s; //License from project: Apache License import java.util.ArrayList; import java.util.List; public class Main { public static List<String> trimElements(List<String> list) { for (int i = 0; i < list.size(); i++) { list.set(i, list.get(i).trim()); }//ww w .ja va 2 s. co m return removeEmptyStrings(list); } /********************************************** * Empty string remover ***********************************************/ private static List<String> removeEmptyStrings(List<String> list) { List<String> result = new ArrayList<String>(); for (String s : list) { if (!isEmpty(s)) { result.add(s); } } return result; } private static boolean isEmpty(String s) { return s == null || s.trim().equals(""); } }