Java Utililty Methods List Trim

List of utility methods to do List Trim

Description

The list of methods to do List Trim are organized into topic(s).

Method

voidaddTrimmed(StringBuffer stringbuffer, java.util.List list, int i)
add Trimmed
int j = i + 1;
stringbuffer.setLength(j);
list.add(stringbuffer.toString());
stringbuffer.setLength(0);
voidaddTrimString(List aStringList, String aString)
add Trim String
String tTrimedString = aString.trim();
if (tTrimedString.length() == 0)
    return;
aStringList.add(tTrimedString);
StringformatSampleText(final List lines, final int maxTrim)
Formats a section of sample text by removing leading whitespace characters up to a given maximum and by flattening lines into a single string.
StringBuilder sb = new StringBuilder();
for (int i = 0; i < lines.size(); i++) {
    sb.append(trimLeadingWhitespace(lines.get(i), maxTrim));
    if (i + 1 < lines.size()) {
        sb.append("\n");
return sb.toString();
...
ListgetTrimmedList(List listA)
Gets the trimmed list.
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;
ListsplitAndTrimCSVToList(String csv)
Return a List (never null) created from the csv string.
if (isBlank(csv)) {
    return Collections.emptyList();
String[] tokens = csv.split(COMMA);
List<String> list = new ArrayList<String>();
for (String token : tokens) {
    list.add(token.trim());
return list;
ListsplitAsList(String source, char delimiter, boolean trim)
Splits a String into substrings along the provided char delimiter and returns the result as a List of Substrings.

List<String> result = new ArrayList<String>();
int i = 0;
int l = source.length();
int n = source.indexOf(delimiter);
while (n != -1) {
    if ((i < n) || ((i > 0) && (i < l))) {
        result.add(trim ? source.substring(i, n).trim() : source.substring(i, n));
    i = n + 1;
    n = source.indexOf(delimiter, i);
if (n < 0) {
    n = source.length();
if (i < n) {
    result.add(trim ? source.substring(i).trim() : source.substring(i));
return result;
ListstringToListTrim(String str, char delimiter)
creates a List from a String "List", trims empty values at start and end
ArrayList list = new ArrayList();
int len = str.length();
if (len == 0)
    return list;
StringBuffer el = new StringBuffer();
boolean hasStart = false;
for (int i = 0; i < len; i++) {
    char c = str.charAt(i);
...
StringtoDelimitedString(List values, String delimiter, boolean trimValues)
to Delimited String
if (values == null || delimiter == null) {
    return null;
StringBuilder stringBuilder = new StringBuilder();
for (int index = 0; index < values.size(); index++) {
    String value = values.get(index);
    String valueToUse = value;
    if (trimValues) {
...
ListtokenizeAndTrimToList(String value, String delimiter)
tokenize And Trim To List
if (value == null) {
    return new ArrayList<String>(0);
value = value.trim();
String[] tokens = value.split(delimiter);
String token;
List<String> result = new ArrayList<String>(tokens.length);
for (int i = 0; i < tokens.length; i++) {
...
ListtoList(final String line, final boolean trimSpaces)
Parses a single line (String) of comma-separated values to a List .
final ArrayList<String> results = new ArrayList<String>();
int i = 0;
final int length = line.length();
while (i < length) {
    final StringBuilder sb = new StringBuilder();
    if (trimSpaces) {
        while (i < length && Character.isWhitespace(line.charAt(i))) {
            ++i;
...