Java Array to String toString(Object[] objects)

Here you can find the source of toString(Object[] objects)

Description

to String

License

Apache License

Declaration

public static String toString(Object[] objects) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.Iterator;

public class Main {
    public static String toString(Object[] objects) {
        return join(", ", objects);
    }/*from w  w  w. j av  a 2s .co m*/

    public static String join(String seperator, Iterator objects) {
        StringBuffer sb = new StringBuffer();
        if (objects.hasNext())
            sb.append(objects.next());
        while (objects.hasNext()) {
            sb.append(seperator).append(objects.next());
        }
        return sb.toString();
    }

    public static String join(String seperator, Object[] objects) {
        int len = objects.length;
        StringBuffer sb = new StringBuffer(len * 2);
        if (len > 0) {
            sb.append(objects[0]);
            for (int i = 1; i < len; i++) {
                sb.append(seperator).append(objects[i]);
            }
        }
        return sb.toString();
    }
}

Related

  1. toString(Object[] a)
  2. toString(Object[] array)
  3. toString(Object[] array)
  4. toString(Object[] array)
  5. toString(Object[] array)
  6. toString(String arrayName, T[] targets)
  7. toString(String[] args, char color1, char color2)
  8. toString(String[] arguments)
  9. toString(String[] array, String delimiter)