Here you can find the source of implode(String glue, String[] pieces)
Parameter | Description |
---|---|
glue | String the source string |
pieces | String[] need to be appended string |
public static String implode(String glue, String[] pieces)
//package com.java2s; public class Main { /**// w ww . j a v a2 s . c o m * join a 'pieces' string array to a string * * @param glue String the source string * @param pieces String[] need to be appended string * @return String */ public static String implode(String glue, String[] pieces) { return implode(glue, pieces, 0); } /** * join a 'pieces' string array to a string * * @param glue String the source string * @param pieces String[] need to be appended string * @param beginIndex int the start index to implode (begin at 0) * @return String */ public static String implode(String glue, String[] pieces, int beginIndex) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < pieces.length; i++) { if (beginIndex != -1 && i < beginIndex) { continue; } if (sb.length() > 0) { sb.append(glue); } sb.append(pieces[i]); } return sb.toString(); } }