print Object Array - Java java.lang

Java examples for java.lang:int Array

Description

print Object Array

Demo Code

/*/*from w ww  . j  ava 2  s.com*/
 * Copyright (c) 2002-2004
 * All rights reserved.
 */
//package com.java2s;
import java.util.Collection;
import java.util.Iterator;

public class Main {
    public static void main(String[] argv) throws Exception {
        Collection valueArrays = java.util.Arrays.asList("asdf",
                "java2s.com");
        printObjectArray(valueArrays);
    }

    public static void printObjectArray(Collection valueArrays) {
        System.out.println("[");
        for (Iterator iterator = valueArrays.iterator(); iterator.hasNext();) {
            Object[] values = (Object[]) iterator.next();

            System.out.print("[");
            for (int i = 0; i < values.length; i++) {
                Object value = values[i];
                System.out.print(value);
                if ((i + 1) < values.length)
                    System.out.print(",");
            }
            System.out.println("]");
        }
        System.out.println("]");
    }
}

Related Tutorials