Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

import java.lang.reflect.Array;
import java.util.*;

public class Main {
    public static Object[][] toMatrix(Iterator[] iterators, Class eachElementType) {
        Object[][] matrix = (Object[][]) Array.newInstance(eachElementType, new int[] { iterators.length, 0 });
        for (int i = 0; i < iterators.length; i++)
            matrix[i] = toArray(iterators[i], eachElementType);

        return matrix;
    }

    public static Object[] toArray(List aList, Class aType) {
        Object[] sameElementsArray = (Object[]) Array.newInstance(aType, aList.size());
        return aList.toArray(sameElementsArray);
    }

    public static Object[] toArray(Iterator anIterator, Class eachElementType) {
        Vector vector = new Vector();
        while (anIterator.hasNext())
            vector.add(anIterator.next());

        return toArray(vector, eachElementType);
    }
}