Here you can find the source of join(List
Parameter | Description |
---|---|
strings | a parameter |
public static String join(List<String> strings)
//package com.java2s; //License from project: Open Source License import java.util.List; public class Main { /**// w w w . j a v a 2 s . com * Join a list of strings by comma. * @param strings * @return */ public static String join(List<String> strings) { return join(strings.toArray(new String[0]), ", "); } /** * Join a list of strings by a separator. * @param strings * @param separator * @return */ public static String join(List<String> strings, String separator) { return join(strings.toArray(new String[0]), separator); } /** * Join an array of strings by comma. * @param strings * @return */ public static String join(String[] strings) { return join(strings, ", "); } /** * Join an array of strings by a separator. * @param strings * @param separator * @return */ public static String join(String[] strings, String separator) { StringBuffer sb = new StringBuffer(); if (strings.length > 0) { sb.append(strings[0]); for (int i = 1; i < strings.length; i++) { sb.append(separator); sb.append(strings[i]); } } return sb.toString(); } }