Java List to String listToString(List s, String separator)

Here you can find the source of listToString(List s, String separator)

Description

convert list value to a string.

License

Apache License

Parameter

Parameter Description
s input string list
separator separator

Return

String

Declaration

public static String listToString(List<String> s, String separator) 

Method Source Code

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

import java.util.List;

public class Main {
    /**/*  w  w w.  ja  v a 2  s  . c o  m*/
     * convert list value to a string.
     * 
     * @param s input string list
     * @param separator separator
     * @return String
     */
    public static String listToString(List<String> s, String separator) {
        return listToString(s, separator, 0);
    }

    /**
     * convert list value to a string.
     * 
     * @param oList oList
     * @param separator separator
     * @param separatorFrPos separatorFrPos
     * @return String
     */
    public static String listToString(List<String> oList, String separator, int separatorFrPos) {
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < oList.size(); i++) {
            if (i > separatorFrPos) {
                sb.append(separator);
            }
            sb.append(oList.get(i));
        }
        return sb.toString();
    }

    /**
     * convert list value to a string array.
     * 
     * @param list
     * @return
     */
    public static String[] listToString(List<String> list) {

        if (list != null && !list.isEmpty()) {

            String[] str = new String[list.size()];

            for (int i = 0; i < list.size(); i++) {
                str[i] = list.get(i);
            }
            return str;
        }
        return null;
    }
}

Related

  1. listToString(List list, String separator)
  2. listToString(List list, String split)
  3. listToString(List params, String sepator)
  4. listToString(List pListToConvert)
  5. listToString(List queryList, String delimitedString)
  6. listToString(List segs, String splitter)
  7. listToString(List stringList)
  8. listToString(List tags)
  9. ListToString(List value, String delimiter)