Here you can find the source of join(Collection s, String delimiter)
Parameter | Description |
---|---|
s | of type Collection |
delimiter | of type String |
Parameter | Description |
---|---|
IllegalArgumentException | an exception |
public static String join(Collection s, String delimiter) throws IllegalArgumentException
//package com.java2s; /*// w w w . j a v a 2s .c om * Copyright (c) 2012. The Genome Analysis Centre, Norwich, UK * MISO project contacts: Robert Davey, Mario Caccamo @ TGAC * ********************************************************************* * * This file is part of MISO. * * MISO is 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 3 of the License, or * (at your option) any later version. * * MISO 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 MISO. If not, see <http://www.gnu.org/licenses/>. * * ********************************************************************* */ import java.util.*; public class Main { /** * Join a collection, akin to Perl's join(), using a given delimiter to produce a single String * * @param s of type Collection * @param delimiter of type String * @return String * @throws IllegalArgumentException */ public static String join(Collection s, String delimiter) throws IllegalArgumentException { if (s == null) { throw new IllegalArgumentException( "Collection to join must not be null"); } StringBuffer buffer = new StringBuffer(); Iterator iter = s.iterator(); while (iter.hasNext()) { buffer.append(iter.next()); if (iter.hasNext() && delimiter != null) { buffer.append(delimiter); } } return buffer.toString(); } /** * Join an Array, akin to Perl's join(), using a given delimiter to produce a single String * * @param s of type Object[] * @param delimiter of type String * @return String */ public static String join(Object[] s, String delimiter) { StringBuffer buffer = new StringBuffer(); for (int i = 0; i < s.length; i++) { buffer.append(s[i]); if (i < s.length - 1) { buffer.append(delimiter); } } return buffer.toString(); } }