Here you can find the source of join(List
Parameter | Description |
---|---|
lst | list for joining |
separator | separator string |
public static String join(List<String> lst, String separator)
//package com.java2s; import java.util.*; public class Main { /**//from ww w . jav a 2s. c om * Joining by separator after each 'not last' value * * @param lst list for joining * @param separator separator string * @return joined string */ public static String join(List<String> lst, String separator) { if (lst == null) return ""; StringBuilder str = new StringBuilder(); Iterator<String> iter = lst.iterator(); while (iter.hasNext()) { str.append(iter.next()); if (iter.hasNext()) { str.append(separator); } } return str.toString(); } }