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

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

Description

Joins an array of shorts, separated by a delimiter.

License

Open Source License

Declaration

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

Method Source Code

//package com.java2s;
/*//  www.  j  a  v a2s .  co  m
 * Copyright (C) 2012  Krawler Information Systems Pvt Ltd
 * All rights reserved.
 * 
 * This program 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 2
 * of the License, or (at your option) any later version.
 * 
 * This program 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 this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

import java.util.Collection;

public class Main {
    /**
     * Joins an array of <code>short</code>s, separated by a delimiter.
     */
    public static String join(String delimiter, short[] array) {
        if (array == null) {
            return null;
        }

        StringBuilder buf = new StringBuilder();

        for (int i = 0; i < array.length; i++) {
            buf.append(array[i]);
            if (i + 1 < array.length) {
                buf.append(delimiter);
            }
        }
        return buf.toString();
    }

    /**
     * Joins an array of objects, separated by a delimiter.
     */
    public static String join(String delimiter, Object[] array) {
        if (array == null) {
            return null;
        }

        StringBuilder buf = new StringBuilder();

        for (int i = 0; i < array.length; i++) {
            buf.append(array[i]);
            if (i + 1 < array.length) {
                buf.append(delimiter);
            }
        }
        return buf.toString();
    }

    public static <E> String join(String delimiter, Collection<E> col) {
        if (col == null) {
            return null;
        }
        Object[] array = new Object[col.size()];
        col.toArray(array);
        return join(delimiter, array);
    }
}

Related

  1. join(Object[] strings, String spliter)
  2. join(Object[] tokens, String delimiter)
  3. join(Object[] values, String join)
  4. join(Object[]... arrays)
  5. join(String delimiter, Object[] strings)
  6. join(String delimiter, String[] array)
  7. join(String delimiter, String[] elements)
  8. join(String delimiter, String[] s)
  9. join(String glue, String[] strings)