Java Array Join join(Object[] array, String delimiter)

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

Description

join

License

Open Source License

Declaration

public static String join(Object[] array, String delimiter) 

Method Source Code


//package com.java2s;
/*//from   w  w w .  ja  v  a 2s  .  c  o  m
 * This file is part of the Raster Storage Archive (RSA).
 *
 * The RSA is free software: you can redistribute it and/or modify it under the
 * terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * The RSA is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * the RSA.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Copyright 2013 CRCSI - Cooperative Research Centre for Spatial Information
 * http://www.crcsi.com.au/
 */

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

public class Main {
    public static String join(Object[] array, String delimiter) {
        return join(Arrays.asList(array), delimiter);
    }

    public static String join(Collection<?> array, String delimiter) {
        if (array.size() == 0)
            return "";

        Iterator<?> iter = array.iterator();
        StringBuilder sb = new StringBuilder();
        sb.append(iter.next().toString());
        while (iter.hasNext()) {
            sb.append(delimiter);
            sb.append(iter.next().toString());
        }
        return sb.toString();
    }
}

Related

  1. join(Object[] array, char separator)
  2. join(Object[] array, char separator)
  3. join(Object[] array, char separator)
  4. join(Object[] array, char separator, int startIndex, int endIndex)
  5. join(Object[] array, String delim)
  6. join(Object[] array, String delimiter)
  7. join(Object[] array, String glue)
  8. join(Object[] array, String linker)
  9. join(Object[] array, String sep)