Java List Trim getTrimmedList(List listA)

Here you can find the source of getTrimmedList(List listA)

Description

Gets the trimmed list.

License

Apache License

Parameter

Parameter Description
listA the list a

Return

the trimmed list

Declaration

public static List<String> getTrimmedList(List<String> listA) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.ArrayList;
import java.util.List;

public class Main {
    /**/*from  w ww . j  a  v  a  2s . c o m*/
     * Gets the trimmed list.
     * 
     * @param listA
     *            the list a
     * @return the trimmed list
     */
    public static List<String> getTrimmedList(List<String> listA) {
        ArrayList<String> newAList = new ArrayList<String>();
        if ((listA != null) && (listA.size() > 0)) {
            for (String aStr : listA) {
                String val = trimToNull(aStr);
                if (null != val) {
                    newAList.add(val);
                }
            }
        }
        return newAList;
    }

    /**
     * Trim to null.
     * 
     * @param value
     *            the value
     * @return the string
     */
    private static String trimToNull(String value) {
        if (null != value) {
            value = value.replaceAll("[\r\n]", "");
            value = value.equals("") ? null : value.trim();

        }
        return value;
    }
}

Related

  1. addTrimmed(StringBuffer stringbuffer, java.util.List list, int i)
  2. addTrimString(List aStringList, String aString)
  3. formatSampleText(final List lines, final int maxTrim)
  4. splitAndTrimCSVToList(String csv)
  5. splitAsList(String source, char delimiter, boolean trim)
  6. stringToListTrim(String str, char delimiter)
  7. toDelimitedString(List values, String delimiter, boolean trimValues)