Java Array to String arrayToString(Object[] arr)

Here you can find the source of arrayToString(Object[] arr)

Description

array To String

License

Open Source License

Declaration

public static String arrayToString(Object[] arr) 

Method Source Code


//package com.java2s;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;

public class Main {
    public static String arrayToString(Object[] arr) {
        return collectionToString(Arrays.asList(arr));
    }/*from   w  ww  . j  a  va2  s.c  o m*/

    public static String collectionToString(Collection c) {
        StringBuffer buff = new StringBuffer();
        int i = 0;
        int size = c.size();
        for (Iterator iter = c.iterator(); iter.hasNext();) {
            Object object = iter.next();
            if (size > 1 && i == (size - 1)) {
                buff.append("and ");
            }
            buff.append(object);
            if (i < (size - 1)) {
                if (size > 2) {
                    buff.append(", ");
                } else {
                    buff.append(" ");
                }
            }
            i++;
        }
        return buff.toString();

    }
}

Related

  1. arrayToString(Object... objects)
  2. arrayToString(Object[] a)
  3. arrayToString(Object[] anArray, String aPrefix, String aSeparator, String aSuffix, String anEscapeChars, char anEscapeSymbol)
  4. arrayToString(Object[] args, String separator)
  5. arrayToString(Object[] arr)
  6. arrayToString(Object[] arr)
  7. arrayToString(Object[] arr)
  8. arrayToString(Object[] arr, String split)
  9. arrayToString(Object[] array)