Here you can find the source of join(String glue, String[] strings)
Parameter | Description |
---|---|
glue | The glue string |
strings | The strings to join |
public static StringBuffer join(String glue, String[] strings)
//package com.java2s; import java.util.Collection; public class Main { /**// w w w . j a v a2s .c o m * Takes a string 'glue' and array of strings, and returns a StringBuffer containing the strings joined with the glue * between each of them. The strings are joined in order * * * @param glue The glue string * @param strings The strings to join * * @return a StringBuffer */ public static StringBuffer join(String glue, String[] strings) { return join(glue, strings, 0, strings.length - 1); } /** * Takes a string 'glue' and array of strings, and returns a StringBuffer containing the strings * between the specified indices (inclusive) joined with the glue between each of them. The strings are joined in order * * @param glue The glue string * @param strings The strings to join * @param first The index of the first string to join * @param last The index of the last string to join * * @return a StringBuffer */ public static StringBuffer join(String glue, String[] strings, int first, int last) { StringBuffer buf = new StringBuffer(); for (int i = first; i <= last; i++) { String s = strings[i]; if (i > first) { buf.append(glue); } buf.append(s); } return buf; } /** * Takes a string 'glue' and collection of CharSequences, and returns a StringBuffer containing the CharSequences * joined with the glue between each of them. They are joined in the order returned by the iterator of the colection * * @param glue The glue string * @param charSequences The CharSequences to join * * @return a StringBuffer */ public static <E> StringBuffer join(String glue, Collection<E> charSequences) { StringBuffer buf = new StringBuffer(); int i = 0; for (Object charSequence : charSequences) { if (i > 0) { buf.append(glue); } buf.append(charSequence); i++; } return buf; } }