Java Iterable implodeStrings(Iterable strings, String glue)

Here you can find the source of implodeStrings(Iterable strings, String glue)

Description

implode Strings

License

Open Source License

Declaration

public static String implodeStrings(Iterable<String> strings, String glue) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2009 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * /*from   w w w.j av  a2  s  .c  o m*/
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *     Zend Technologies
 *******************************************************************************/

import java.util.Iterator;

public class Main {
    public static String implodeStrings(Iterable<String> strings, String glue) {
        StringBuffer stringBuffer = new StringBuffer();
        for (Iterator<String> i = strings.iterator(); i.hasNext();) {
            String varClassName = i.next();
            stringBuffer.append(varClassName);
            if (i.hasNext()) {
                stringBuffer.append(glue);
            }
        }
        return stringBuffer.toString();
    }
}

Related

  1. getElement(final Iterable iterable, int index)
  2. getIdenticalElement(Iterable iterable)
  3. getLongestCommonToken(Iterable iterable, char tokenSeparatorChar)
  4. getMessageString(Iterable msgs)
  5. getUnique(Iterable iterable)
  6. indexOfSame(Iterable iterable, T obj)
  7. internalSeparate(StringBuilder buff, Iterable args, String separator, String useWhenNone)
  8. isEmpty(Iterable iterable)
  9. isEmpty(Iterable i)