Java List Trim trimElements(List list)

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

Description

trim Elements

License

Apache License

Declaration

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

Method Source Code


//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("");
    }
}

Related

  1. toList(final String line, final boolean trimSpaces)
  2. toStringList(List list, String delimiter, boolean isTrim, boolean isRemoveEmpty)
  3. trim(final List row)
  4. trim(List data, boolean removeEmptyLines)
  5. trim(List strs)
  6. trimEndDigital(List strs)
  7. trimIfLastIndex(List suggestedList, String suggestedWords, int i)
  8. trimKeyFormat(String s3KeyFormat, List disallowedKeys)
  9. trimLeadingWhitespaces(List lines)