Here you can find the source of join(List
Parameter | Description |
---|---|
values | the List of String s to join. |
delimiter | the delimiter |
public static String join(List<String> values, String delimiter)
//package com.java2s; //License from project: Open Source License import java.util.List; public class Main { /**//from w ww .j av a2 s . c o m * Join a given {@link List} of {@link String}s, separated by a given delimiter. * * @param values the {@link List} of {@link String}s to join. * @param delimiter the delimiter * @return the joined {@link String} */ public static String join(List<String> values, String delimiter) { StringBuilder sb = new StringBuilder(); if (values != null && !values.isEmpty()) { sb.append(values.get(0)); for (int i = 1; i < values.size(); i++) { sb.append(delimiter); sb.append(values.get(i)); } } return sb.toString(); } }