Here you can find the source of join(Collection col, char sep)
Parameter | Description |
---|---|
col | the col |
sep | the sep |
public static String join(Collection col, char sep)
//package com.java2s; /*/*from ww w . j a v a 2 s . c o m*/ Copyright (C) 2010 by * * Cam-Tu Nguyen * ncamtu@ecei.tohoku.ac.jp or ncamtu@gmail.com * * Xuan-Hieu Phan * pxhieu@gmail.com * * College of Technology, Vietnamese University, Hanoi * Graduate School of Information Sciences, Tohoku University * * JVnTextPro-v.2.0 is a free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published * by the Free Software Foundation; either version 2 of the License, * or (at your option) any later version. * * JVnTextPro-v.2.0 is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with JVnTextPro-v.2.0); if not, write to the Free Software Foundation, * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ import java.util.Collection; public class Main { /** * Join the <tt>String</tt> representations of an array of objects, with the specified * separator. * * @param objects the objects * @param sep the sep * @return newly created . */ public static String join(Object[] objects, char sep) { if (objects.length == 0) { return ""; } StringBuffer buffer = new StringBuffer(objects[0].toString()); for (int i = 1; i < objects.length; i++) { buffer.append(sep); buffer.append(objects[i].toString()); } return buffer.toString(); } /** * Join the <tt>String</tt> representations of a collection of objects, with the specified * separator. * * @param col the col * @param sep the sep * @return newly created . */ public static String join(Collection col, char sep) { if (col.isEmpty()) { return ""; } StringBuffer buffer = new StringBuffer(); boolean first = true; for (Object o : col) { if (first) { first = false; } else { buffer.append(sep); } buffer.append(o.toString()); } return buffer.toString(); } }