Java List Trim toDelimitedString(List values, String delimiter, boolean trimValues)

Here you can find the source of toDelimitedString(List values, String delimiter, boolean trimValues)

Description

to Delimited String

License

Open Source License

Declaration

public static String toDelimitedString(List<String> values, String delimiter, boolean trimValues) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.List;

public class Main {
    public static String toDelimitedString(List<String> values, String delimiter, boolean trimValues) {

        if (values == null || delimiter == null) {
            return null;
        }/*from ww  w .  java2 s .  c o  m*/

        StringBuilder stringBuilder = new StringBuilder();

        for (int index = 0; index < values.size(); index++) {
            String value = values.get(index);

            String valueToUse = value;
            if (trimValues) {
                valueToUse = valueToUse.trim();
            }

            if (index > 0) {
                stringBuilder.append(delimiter);
            }

            stringBuilder.append(valueToUse);
        }

        String delimitedString = stringBuilder.toString();

        return delimitedString;

    }
}

Related

  1. formatSampleText(final List lines, final int maxTrim)
  2. getTrimmedList(List listA)
  3. splitAndTrimCSVToList(String csv)
  4. splitAsList(String source, char delimiter, boolean trim)
  5. stringToListTrim(String str, char delimiter)
  6. tokenizeAndTrimToList(String value, String delimiter)
  7. toList(final String line, final boolean trimSpaces)
  8. toStringList(List list, String delimiter, boolean isTrim, boolean isRemoveEmpty)
  9. trim(final List row)