Java Collection Join join(String c, Collection d)

Here you can find the source of join(String c, Collection d)

Description

Similar to join / implode in php.

License

Open Source License

Declaration

public static String join(String c, Collection d) 

Method Source Code

//package com.java2s;
/*/*www  .j  a v a  2 s .c o  m*/
 * Copyright (C) 2007 by Instytut Podstaw Informatyki Polskiej
 * Akademii Nauk (IPI PAN; Institute of Computer Science, Polish
 * Academy of Sciences; cf. www.ipipan.waw.pl).  All rights reserved.
 *
 * This file is part of Spejd.
 *
 * Spejd is free software: it may be distributed and/or modified under 
 * the terms of the GNU General Public License version 3 as published 
 * by the Free Software Foundation and appearing in the file doc/gpl.txt
 * included in the packaging of this file.
 *
 * A commercial license is available from IPI PAN (contact
 * Michal.Ciesiolka@ipipan.waw.pl or ipi@ipipan.waw.pl for more
 * information).  Licensees holding a valid commercial license from IPI
 * PAN may use this file in accordance with that license.
 *
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE.
 */

import java.util.Collection;
import java.util.Iterator;

public class Main {
    /**
     * Similar to join / implode in php.
     */
    public static String join(String c, Collection d) {
        StringBuilder res = new StringBuilder();
        boolean notFirst = false;
        for (Iterator i = d.iterator(); i.hasNext();) {
            if (notFirst)
                res.append(c);
            else
                notFirst = true;
            res.append(i.next());
        }
        return res.toString();
    }
}

Related

  1. join(final String separator, final Collection objects)
  2. join(final String separator, final Collection objects)
  3. join(final String separator, final Collection objects)
  4. join(Iterable collection, String delimiter)
  5. join(Iterable collection)
  6. join(String delim, Collection list)
  7. join(String delim, Collection col)
  8. join(String delim, Collection values)
  9. join(String delim, Collection collections)