Here you can find the source of join(List
public static String join(List<String> list)
//package com.java2s; /**/*from w w w . j av a 2s . c o m*/ * Copyright (c) 2014 http://www.lushapp.wang * * Licensed under the Apache License, Version 2.0 (the "License"); */ import java.util.List; public class Main { private static final String defaultSeparator = ","; public static String join(List<String> list) { return join(list, getDefaultSeparator()); } public static String join(List<String> list, char separator) { return join(list, separator + ""); } public static String join(List<String> list, String separator) { if (isEmpty(list)) { return ""; } if (separator == null) { separator = getDefaultSeparator(); } StringBuilder joinStr = new StringBuilder(); for (String entry : list) { joinStr.append(entry).append(separator); } int lastIndexOfPosi = joinStr.lastIndexOf(separator); if (lastIndexOfPosi != -1 && lastIndexOfPosi == (joinStr.length() - separator.length())) { return joinStr.substring(0, joinStr.length() - separator.length()); } return joinStr.toString(); } public static String getDefaultSeparator() { return defaultSeparator; } public static boolean isEmpty(List<?> sourceList) { return (sourceList == null || sourceList.size() == 0); } }