Here you can find the source of join(AbstractCollection
Parameter | Description |
---|---|
s | : Collection <String> |
delimiter | : String |
public static String join(AbstractCollection<String> s, String delimiter)
//package com.java2s; /*/*from w ww . j a v a 2 s .co m*/ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 2013 BiBiServ Curator Team, http://bibiserv.cebitec.uni-bielefeld.de, * All rights reserved. * * The contents of this file are subject to the terms of the Common * Development and Distribution License("CDDL") (the "License"). You * may not use this file except in compliance with the License. You can * obtain a copy of the License at http://www.sun.com/cddl/cddl.html * * See the License for the specific language governing permissions and * limitations under the License. When distributing the software, include * this License Header Notice in each file. If applicable, add the following * below the License Header, with the fields enclosed by brackets [] replaced * by your own identifying information: * * "Portions Copyrighted 2013 BiBiServ Curator Team" * * Contributor(s): Jan Krueger * */ import java.util.AbstractCollection; import java.util.Iterator; public class Main { /** * Join a Collection of Strings using a delimiter * * @param s : Collection <String> * @param delimiter : String * @return joined String */ public static String join(AbstractCollection<String> s, String delimiter) { if (s == null || s.isEmpty()) { return ""; } Iterator<String> iter = s.iterator(); StringBuilder builder = new StringBuilder(iter.next()); while (iter.hasNext()) { builder.append(delimiter).append(iter.next()); } return builder.toString(); } /** * Join a collection of Strings using a delimiter * * @param s : Collection<String> * @return joined String */ public static String join(AbstractCollection<String> s) { return join(s, ""); } /** * Join an Array of Strings * * @param s : String [] * @param delimiter : String * @return joined String */ public static String join(String s[], String delimiter) { if (s == null || s.length == 0) { return ""; } StringBuilder sb = new StringBuilder(s[0]); for (int i = 1; i < s.length; ++i) { sb.append(delimiter).append(s[i]); } return sb.toString(); } /** * Join an Array of Strings * * @param s : String [] * @return joined String */ public static String join(String s[]) { return join(s, ""); } }