Java Array Join join(String[] array)

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

Description

Joins the the array elements to a string delimited by '\t'

License

Open Source License

Parameter

Parameter Description
array a parameter

Return

string joined array

Declaration

public static String join(String[] array) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.*;

public class Main {
    /**//from   w  w  w .  ja  v a2s  . c  om
     * Joins the the list elements to a string
     * delimited by '\t'
     * @param collection
     * @return string joined array
     */
    public static String join(Collection<?> collection) {
        return join(collection, '\t');
    }

    /**
     * Joins the the array elements to a string
     * delimited by '\t'
     * @param array
     * @return string joined array
     */
    public static String join(String[] array) {
        return join(array, '\t');
    }

    /**
     * Joins the the collection elements to a string
     * delimited by the submitted delimiter
     * @param collection
     * @param delimiter
     * @return string joined array
     */
    public static String join(Collection<?> collection, Character delimiter) {
        if (collection == null || collection.size() == 0)
            return null;
        StringBuilder sb = new StringBuilder();
        Iterator<?> it = collection.iterator();
        sb.append(it.next());
        while (it.hasNext()) {
            sb.append(delimiter);
            sb.append(it.next());
        }
        return sb.toString();
    }

    /**
     * Joins the the collection elements to a string
     * delimited by the submitted delimiter
     * @param collection
     * @param delimiter
     * @return string joined array
     */
    public static String join(Collection<?> collection, String delimiter) {
        if (collection == null || collection.size() == 0)
            return null;
        StringBuilder sb = new StringBuilder();
        Iterator<?> it = collection.iterator();
        sb.append(it.next());
        while (it.hasNext()) {
            sb.append(delimiter);
            sb.append(it.next());
        }
        return sb.toString();
    }

    /**
     * Joins the the array elements to a string
     * delimited by the submitted delimiter
     * @param array
     * @param delimiter
     * @return string joined array
     */
    public static String join(String[] array, Character delimiter) {
        if (array == null)
            return null;
        int length = array.length;
        if (length == 0)
            return null;
        StringBuilder sb = new StringBuilder();
        sb.append(array[0]);
        for (int i = 1; i < length; i++) {
            sb.append(delimiter);
            sb.append(array[i]);
        }
        return sb.toString();
    }

    /**
     * Joins the the array elements to a string
     * delimited by the submitted delimiter
     * @param array
     * @param delimiter
     * @return string joined array
     */
    public static String join(String[] array, String delimiter) {
        if (array == null)
            return null;
        int length = array.length;
        if (length == 0)
            return null;
        StringBuilder sb = new StringBuilder();
        sb.append(array[0]);
        for (int i = 1; i < length; i++) {
            sb.append(delimiter);
            sb.append(array[i]);
        }
        return sb.toString();
    }
}

Related

  1. join(String[] args)
  2. join(String[] args, String delimiter)
  3. join(String[] array)
  4. join(String[] array)
  5. join(String[] array)
  6. join(String[] array)
  7. join(String[] array, String delim)
  8. join(String[] array, String delimiter)
  9. join(String[] array, String delimiter)