Here you can find the source of join(String[] lines, String delim)
Parameter | Description |
---|---|
lines | a <code>String[]</code> value |
delim | a <code>char</code> value |
String
value
public static String join(String[] lines, String delim)
//package com.java2s; /* J_LZ_COPYRIGHT_BEGIN ******************************************************* * Copyright 2001-2006, 2011 Laszlo Systems, Inc. All Rights Reserved. * * Use is subject to license terms. * * J_LZ_COPYRIGHT_END *********************************************************/ import java.util.*; public class Main { /**//from ww w .j av a 2 s . c o m * Returns a single string that interpolates the strings in * <var>lines</var> by the delimiters <var>delim</var>. * * For example, <code>join({"a","b","c"}, ",")</code> would * evaluate to <code>"a,b,c"</code> (if Java had a literal * expression notation for arrays). * * @param lines a <code>String[]</code> value * @param delim a <code>char</code> value * @return a <code>String</code> value */ public static String join(String[] lines, String delim) { StringBuilder buffer = new StringBuilder(); for (int i = 0; i < lines.length; i++) { if (i > 0) { buffer.append(delim); } buffer.append(lines[i]); } return buffer.toString(); } /** List<String>, String -> String */ public static String join(List<String> words, String delim) { StringBuilder buffer = new StringBuilder(); for (Iterator<String> iter = words.iterator(); iter.hasNext();) { buffer.append(iter.next()); if (iter.hasNext()) { buffer.append(delim); } } return buffer.toString(); } }