Java Array Concatenate concatenate(Object[] array)

Here you can find the source of concatenate(Object[] array)

Description

concatenate

License

Open Source License

Declaration

public static String concatenate(Object[] array) 

Method Source Code

//package com.java2s;
/**/*  w  w w.ja  v  a2s  .c  o  m*/
 *  ETRI Distributed Resource/Mediation System for new re-generation Energy Exchange
 *
 *  Copyright ? [2016] ETRI. All rights reserved.
 *
 *    This is a proprietary software of ETRI, and you may not use this file except in
 *  compliance with license agreement with ETRI. Any redistribution or use of this
 *  software, with or without modification shall be strictly prohibited without prior written
 *  approval of ETRI, and the copyright notice above does not evidence any actual or
 *  intended publication of such software.
 *
 * com.nc.common.utils : StringUtil.java
 * @author creme55
 * @since 2016. 10. 12.
 * @version 1.0
 * @see 
 * @Copyright ? [2016] By ETRI. All rights reserved.
 *
 * <pre>
 * << ??????(Modification Information) >>
 *      ?????              ????                  ????
 *  -------------        -----------       -------------------------
 *  2016. 10. 12.          creme55         ?? ???(???? ?? ????)              
 *
 * </pre>
 **/

import java.util.Iterator;

public class Main {
    public static final String EMPTY = "";

    public static String concatenate(Object[] array) {
        return join(array, null);
    }

    public static String join(Object[] array) {
        return join(array, null);
    }

    public static String join(Object[] array, char separator) {
        if (array == null) {
            return null;
        }
        int arraySize = array.length;
        int bufSize = (arraySize == 0 ? 0
                : ((array[0] == null ? 16 : array[0].toString().length()) + 1) * arraySize);
        StringBuffer buf = new StringBuffer(bufSize);

        for (int i = 0; i < arraySize; i++) {
            if (i > 0) {
                buf.append(separator);
            }
            if (array[i] != null) {
                buf.append(array[i]);
            }
        }
        return buf.toString();
    }

    public static String join(Object[] array, String separator) {
        if (array == null) {
            return null;
        }
        if (separator == null) {
            separator = EMPTY;
        }
        int arraySize = array.length;

        int bufSize = ((arraySize == 0) ? 0
                : arraySize * ((array[0] == null ? 16 : array[0].toString().length())
                        + ((separator != null) ? separator.length() : 0)));

        StringBuffer buf = new StringBuffer(bufSize);

        for (int i = 0; i < arraySize; i++) {
            if ((separator != null) && (i > 0)) {
                buf.append(separator);
            }
            if (array[i] != null) {
                buf.append(array[i]);
            }
        }
        return buf.toString();
    }

    @SuppressWarnings("rawtypes")
    public static String join(Iterator iterator, char separator) {
        if (iterator == null) {
            return null;
        }
        StringBuffer buf = new StringBuffer(256); // Java default is 16,
        // probably too small
        while (iterator.hasNext()) {
            Object obj = iterator.next();
            if (obj != null) {
                buf.append(obj);
            }
            if (iterator.hasNext()) {
                buf.append(separator);
            }
        }
        return buf.toString();
    }

    @SuppressWarnings("rawtypes")
    public static String join(Iterator iterator, String separator) {
        if (iterator == null) {
            return null;
        }
        StringBuffer buf = new StringBuffer(256); // Java default is 16,
        // probably too small
        while (iterator.hasNext()) {
            Object obj = iterator.next();
            if (obj != null) {
                buf.append(obj);
            }
            if ((separator != null) && iterator.hasNext()) {
                buf.append(separator);
            }
        }
        return buf.toString();
    }

    public static String toString(int value) {
        return Integer.toString(value);
    }
}

Related

  1. concatenate(byte[] a, byte[] b)
  2. concatenate(double[] p1, double[] p2)
  3. concatenate(float[][] a, float[][] b, int dim)
  4. concatenate(int[]... arrays)
  5. concatenate(Object[] array)
  6. concatenate(Object[] array)
  7. concatenate(Object[] array)
  8. concatenate(Object[] collection)
  9. concatenate(String[] args)