Here you can find the source of join(List extends Object> words, String iDelimiter)
Parameter | Description |
---|---|
words | - array of words to join into a single string. |
iDelimiter | - the delimiter to use between each two words. |
public static String join(List<? extends Object> words, String iDelimiter)
//package com.java2s; // Licensed under the terms of the New BSD License. Please see associated LICENSE file for terms. import java.util.List; public class Main { /**/*from ww w . j a va 2 s .c om*/ * Join a list of words into a single string using the specified delimiter. * * @param words - array of words to join into a single string. * @param iDelimiter - the delimiter to use between each two words. * @return A string constructed from the words separated with the delimiter. */ public static String join(List<? extends Object> words, String iDelimiter) { StringBuilder str = new StringBuilder(); if (words.size() == 0) { return str.toString(); } int i; for (i = 0; i < words.size() - 1; i++) { str.append(words.get(i)); str.append(iDelimiter); } str.append(words.get(i)); return str.toString(); } /** * Join an array of words into a single string using the specified delimiter. * * @param words - array of words to join into a single string. * @param iDelimiter - the delimiter to use between each two words. * @return A string constructed from the words separated with the delimiter. */ public static String join(String[] words, String iDelimiter) { StringBuilder str = new StringBuilder(); if (words.length == 0) { return str.toString(); } int i; for (i = 0; i < words.length - 1; i++) { str.append(words[i]); str.append(iDelimiter); } str.append(words[i]); return str.toString(); } }