Here you can find the source of join(List
Parameter | Description |
---|---|
list | a list value that need to join. |
joiner | The joiner that used to join the list. |
public static <T> String join(List<T> list, String joiner)
//package com.java2s; import java.util.List; public class Main { /**/*w w w . j a va 2 s .c o m*/ * Join the list with joiner. * @param list a list value that need to join. * @param joiner The joiner that used to join the list. * @return the joined string. * @since 1.0 (TopCoder Direct API Setup and implement My Created Challenges API) */ public static <T> String join(List<T> list, String joiner) { StringBuilder stringBuilder = new StringBuilder(); if (list == null) { return null; } if (list.isEmpty()) { return ""; } for (T s : list) { stringBuilder.append(s).append(joiner); } stringBuilder.delete(stringBuilder.length() - joiner.length(), stringBuilder.length()); return stringBuilder.toString(); } }