Here you can find the source of join(String[] stringArray, String delimiter)
public static String join(String[] stringArray, String delimiter)
//package com.java2s; /*L/*from w w w . j a v a 2 s .c o m*/ * Copyright SAIC * Copyright SAIC-Frederick * * Distributed under the OSI-approved BSD 3-Clause License. * See http://ncip.github.com/cananolab/LICENSE.txt for details. */ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; public class Main { public static String join(String[] stringArray, String delimiter) { String joinedStr = ""; if (stringArray == null || stringArray.length == 0) { return joinedStr; } List<String> stringList = Arrays.asList(stringArray); return join(stringList, delimiter); } public static String join(Collection<String> stringList, String delimiter) { String joinedStr = ""; if (stringList == null || stringList.isEmpty()) { return joinedStr; } // remove empty items Collection<String> modList = new ArrayList<String>(stringList); for (String str : modList) { if (isEmpty(str)) { stringList.remove(str); } } StringBuilder sb = new StringBuilder(); int i = 0; for (String str : stringList) { if (i < stringList.size() - 1) { sb.append(str); sb.append(delimiter); } else { sb.append(str); } i++; } joinedStr = sb.toString(); return joinedStr; } /** * Return true for Null or empty string, false otherwise. */ public static boolean isEmpty(String str) { return (str == null || str.trim().length() == 0); } }