Here you can find the source of joinObjects(Collection
public static String joinObjects(Collection<Object> objects)
//package com.java2s; /*// w ww. jav a 2 s . c o m * Copyright 2012 University of Helsinki. * * This file is part of BMVis?. * * BMVis? is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * BMVis? 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with BMVis?. If not, see * <http://www.gnu.org/licenses/>. */ import java.util.Collection; public class Main { public static String joinObjects(Collection<Object> objects) { return joinObjects(objects, ""); } public static String joinObjects(Collection<Object> objects, String delimiter) { StringBuffer buf = new StringBuffer(); for (Object item : objects) { if (item == null) buf.append("null"); else if (item instanceof String) buf.append(item); else buf.append(item.toString()); buf.append(delimiter); } if (buf.length() > delimiter.length() && buf.substring(buf.length() - delimiter.length() - 1, buf.length() - 1).equals(delimiter)) return buf.substring(buf.length() - delimiter.length() - 2); return buf.toString(); } }