Java Array to String toString(T[] array)

Here you can find the source of toString(T[] array)

Description

to String

License

Open Source License

Declaration

public static <T> String toString(T[] array) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;

import java.util.List;

public class Main {
    public static <T> String toString(Collection<T> collection) {
        if (collection == null) {
            return "NULL";
        }//from  w w  w.j  a  v a  2  s . c  om
        String out = "[ ";
        int count = 1;
        for (T object : collection) {
            if (object == null)
                continue;
            out = out + object.toString();
            if (collection.size() != count) {
                out = out + ";\n";
            }
            count++;
        }
        out = out + " ]";
        return out;
    }

    public static <T> String toString(T[] array) {
        return toString(Arrays.asList(array));
    }

    public static <T> List<T> asList(Collection<T> collection) {
        return new ArrayList<T>(collection);
    }
}

Related

  1. toString(String[] args, char color1, char color2)
  2. toString(String[] arguments)
  3. toString(String[] array, String delimiter)
  4. toString(String[] line)
  5. toString(String[] paramNames, Object[] params)
  6. toString(T[] array)
  7. toString(T[] array, String prefix, String sep, String suffix)
  8. toStringArray(Collection strings)
  9. toStringArray(Dictionary props, String key, String[] defaultArray)