Print collection to console - Java java.util

Java examples for java.util:Collection Operation

Description

Print collection to console

Demo Code


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

public class Main {
    public static void main(String[] argv) {
        Collection collection = java.util.Arrays.asList("asdf",
                "java2s.com");
        display(collection);/*  www . ja  v a2  s.  co  m*/
    }

    public static void display(Collection collection) {
        Iterator iterator = collection.iterator();
        while (iterator.hasNext()) {
            System.out.print(iterator.next() + " ");
        }
        System.out.println();
    }
}

Related Tutorials