Here you can find the source of listToString(List
Parameter | Description |
---|---|
s | input string list |
separator | separator |
public static String listToString(List<String> s, String separator)
//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; } }