Java Array Join join(T[] array, String separator)

Here you can find the source of join(T[] array, String separator)

Description

join

License

Open Source License

Declaration

public static <T> String join(T[] array, String separator) 

Method Source Code

//package com.java2s;
/*//w  ww.ja v  a2s  . c  o m
 * Copyright (c) 2012 The ANTLR Project. All rights reserved.
 * Use of this file is governed by the BSD-3-Clause license that
 * can be found in the LICENSE.txt file in the project root.
 */

import java.util.Arrays;

import java.util.Iterator;

public class Main {
    /**
     * @sharpen.ignore
     */
    public static String join(Iterable<?> iter, String separator) {
        return join(iter.iterator(), separator);
    }

    /**
     * @sharpen.ignore
     */
    public static <T> String join(T[] array, String separator) {
        return join(Arrays.asList(array), separator);
    }

    /**
     * @sharpen.ignore
     */
    public static <T> String join(Iterator<T> iter, String separator) {
        StringBuilder buf = new StringBuilder();
        while (iter.hasNext()) {
            buf.append(iter.next());
            if (iter.hasNext()) {
                buf.append(separator);
            }
        }
        return buf.toString();
    }
}

Related

  1. join(T[] a, T[] b)
  2. join(T[] arr1, T[] arr2)
  3. join(T[] array, String join)
  4. join(T[] array, String separator)
  5. join(T[] array, String separator)
  6. join(T[] array, String separator)
  7. join(T[] array, String separator)
  8. join(T[] array1, T[] array2)
  9. join(T[] first, T[] second)