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.util.ArrayList;
import java.util.Arrays;

public class Main {
    public static <T> T[] remove(T[] current, T queueId) {
        ArrayList<T> asList = asList(current);
        asList.remove(queueId);
        T[] result = current.clone();
        return asList.toArray(result);
    }

    public static ArrayList<Integer> asList(int[] intArray) {
        if (intArray == null)
            return null;
        ArrayList<Integer> list = new ArrayList<Integer>();
        for (int i : intArray) {
            list.add(i);
        }
        return list;
    }

    public static ArrayList<Long> asList(long[] longArray) {
        if (longArray == null)
            return null;
        ArrayList<Long> list = new ArrayList<Long>();
        for (long i : longArray) {
            list.add(i);
        }
        return list;
    }

    public static ArrayList<Double> asList(double[] doubleArray) {
        if (doubleArray == null)
            return null;
        ArrayList<Double> list = new ArrayList<Double>();
        for (double i : doubleArray) {
            list.add(i);
        }
        return list;
    }

    public static ArrayList<Float> asList(float[] floatArray) {
        if (floatArray == null)
            return null;
        ArrayList<Float> list = new ArrayList<Float>();
        for (float i : floatArray) {
            list.add(i);
        }
        return list;
    }

    public static ArrayList<Boolean> asList(boolean[] booleanArray) {
        if (booleanArray == null)
            return null;
        ArrayList<Boolean> list = new ArrayList<Boolean>();
        for (boolean i : booleanArray) {
            list.add(i);
        }
        return list;
    }

    public static <T> ArrayList<T> asList(T[] array) {
        if (array == null)
            return null;
        return new ArrayList<T>(Arrays.asList(array));
    }

    public static <T> T[] add(T[] current, T queueId) {
        ArrayList<T> asList = asList(current);
        asList.add(queueId);
        T[] result = current.clone();
        return asList.toArray(result);
    }
}