Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

public class Main {
    public static int[] toIntArray(String[] ss) {
        int[] r = new int[ss.length];
        for (int i = 0; i < r.length; i++) {
            r[i] = Integer.valueOf(ss[i]);
        }
        return r;
    }

    public static int[] toIntArray(List<Integer> list) {
        return toPrimitive(list.toArray(new Integer[0]));
    }

    public static int[] toPrimitive(Integer[] array) {
        int[] r = new int[array.length];
        for (int i = 0; i < array.length; i++) {
            r[i] = array[i];
        }
        return r;
    }

    public static long[] toArray(Iterator<Long> it) {
        List<Long> list = toList(it);
        return toArray(list);
    }

    public static long[] toArray(Collection<Long> collection) {
        long[] array = new long[collection.size()];
        Iterator<Long> it = collection.iterator();
        int i = 0;
        while (it.hasNext()) {
            array[i++] = it.next();
        }
        return array;
    }

    public static List<Long> toList(Iterator<Long> it) {
        List<Long> list = new ArrayList<Long>();
        while (it.hasNext()) {
            list.add(it.next());
        }
        return list;
    }
}