Java List Trim trimList(List list)

Here you can find the source of trimList(List list)

Description

trim List

License

Open Source License

Declaration

public static List<String> trimList(List<String> list) 

Method Source Code

//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;
    }
}

Related

  1. trimElements(List list)
  2. trimEndDigital(List strs)
  3. trimIfLastIndex(List suggestedList, String suggestedWords, int i)
  4. trimKeyFormat(String s3KeyFormat, List disallowedKeys)
  5. trimLeadingWhitespaces(List lines)
  6. trimList(List source)
  7. trimListValues(List original)
  8. trimSequence(int m, List sequence)
  9. trimStringLineList(List lines)