Java Iterable Join join(String sep, Iterable strings)

Here you can find the source of join(String sep, Iterable strings)

Description

join

License

Open Source License

Declaration

public static String join(String sep, Iterable<String> strings) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2009, 2014 Xored Software Inc 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
 *
 * Contributors:/*from  ww  w  .j av  a  2  s. co  m*/
 *     Xored Software Inc - initial API and implementation and/or initial documentation
 *******************************************************************************/

import java.util.Iterator;

public class Main {
    public static String join(char sep, Iterable<String> strings) {
        return join(Character.toString(sep), strings);
    }

    public static String join(char sep, Iterator<String> strings) {
        return join(Character.toString(sep), strings);
    }

    public static String join(String sep, Iterable<String> strings) {
        return join(sep, strings.iterator());
    }

    public static String join(String sep, Iterator<String> strings) {
        StringBuilder sb = new StringBuilder();
        while (strings.hasNext()) {
            sb.append(strings.next());
            sb.append(sep);
        }
        if (sb.length() > 0) {
            sb.setLength(sb.length() - sep.length());
        }
        return sb.toString();
    }
}

Related

  1. join(String delimiter, Iterable strings)
  2. join(String delimiter, Iterable stringsIterable)
  3. join(String delimiter, String wrap, Iterable objs)
  4. join(String glue, Iterable pieces)
  5. join(String glue, Iterable tokens)
  6. join(String separator, Iterable elements)
  7. join(String separator, Iterable objects)
  8. join(String separator, Iterable args)
  9. join(String seperator, Iterator objects)