Java List Create createDelimitedString(String rawListAsString)

Here you can find the source of createDelimitedString(String rawListAsString)

Description

create Delimited String

License

Open Source License

Declaration

public static String createDelimitedString(String rawListAsString) 

Method Source Code


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

import java.util.List;
import java.util.Arrays;

public class Main {
    private static final String DEFAULT_DELIMITER = "    ";
    private static final String REGEX_TO_SPLIT = "[\\s]+";

    public static String createDelimitedString(String rawListAsString) {
        return createDelimitedString(rawListAsString, null);
    }/*w ww .j a va  2 s  . c  om*/

    public static String createDelimitedString(String rawListAsString, String delimiter) {
        if (rawListAsString == null)
            return null;

        String[] argList = rawListAsString.trim().split(REGEX_TO_SPLIT);
        List<String> list = Arrays.asList(argList);

        return createDelimitedString(list, delimiter);
    }

    public static String createDelimitedString(List<String> list) {
        return createDelimitedString(list, null);
    }

    public static String createDelimitedString(List<String> list, String delimiter) {
        if (delimiter == null)
            delimiter = DEFAULT_DELIMITER;
        if (list == null)
            return null;

        /* todo: maybe replace with StringUtils later */
        StringBuffer buffer = new StringBuffer();
        for (String item : list) {
            buffer.append(item.trim());
            if (list.indexOf(item) < list.size() - 1) {
                buffer.append(delimiter);
            }
        }
        return buffer.toString().trim();
    }
}

Related

  1. createConfusionMatrix(HashMap> tempM, List actualLabelsList, List predictedLabelsList)
  2. createConsultInfoMap(List resAry)
  3. createCSVLine(final char textQ, final char fieldD, final List values)
  4. createDefaultGroup(String name, String prefabGroup, List nodes)
  5. createDefaultValueList(int capacity, T defaultValue)
  6. createDoubleList(double[] values)
  7. createDriverSheetNames(List driverBeans)
  8. createEmptyAdjacencyList(int n)
  9. createEmptyList(Class type)

  10. HOME | Copyright © www.java2s.com 2016