Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static boolean[] combine(boolean[]... arrays) {
        int totalLength = 0;
        for (boolean[] booleans : arrays) {
            totalLength += booleans.length;
        }
        boolean[] newArray = new boolean[totalLength];
        int pointer = 0;
        for (boolean[] booleans : arrays) {
            System.arraycopy(booleans, 0, newArray, pointer, booleans.length);
            pointer += booleans.length;
        }
        return newArray;
    }

    public static byte[] combine(byte[]... arrays) {
        int totalLength = 0;
        for (byte[] bytes : arrays) {
            totalLength += bytes.length;
        }
        byte[] newArray = new byte[totalLength];
        int pointer = 0;
        for (byte[] bytes : arrays) {
            System.arraycopy(bytes, 0, newArray, pointer, bytes.length);
            pointer += bytes.length;
        }
        return newArray;
    }

    public static char[] combine(char[]... arrays) {
        int totalLength = 0;
        for (char[] chars : arrays) {
            totalLength += chars.length;
        }
        char[] newArray = new char[totalLength];
        int pointer = 0;
        for (char[] chars : arrays) {
            System.arraycopy(chars, 0, newArray, pointer, chars.length);
            pointer += chars.length;
        }
        return newArray;
    }

    public static double[] combine(double[]... arrays) {
        int totalLength = 0;
        for (double[] doubles : arrays) {
            totalLength += doubles.length;
        }
        double[] newArray = new double[totalLength];
        int pointer = 0;
        for (double[] doubles : arrays) {
            System.arraycopy(doubles, 0, newArray, pointer, doubles.length);
            pointer += doubles.length;
        }
        return newArray;
    }

    public static float[] combine(float[]... arrays) {
        int totalLength = 0;
        for (float[] floats : arrays) {
            totalLength += floats.length;
        }
        float[] newArray = new float[totalLength];
        int pointer = 0;
        for (float[] floats : arrays) {
            System.arraycopy(floats, 0, newArray, pointer, floats.length);
            pointer += floats.length;
        }
        return newArray;
    }

    public static int[] combine(int[]... arrays) {
        int totalLength = 0;
        for (int[] ints : arrays) {
            totalLength += ints.length;
        }
        int[] newArray = new int[totalLength];
        int pointer = 0;
        for (int[] ints : arrays) {
            System.arraycopy(ints, 0, newArray, pointer, ints.length);
            pointer += ints.length;
        }
        return newArray;
    }

    public static long[] combine(long[]... arrays) {
        int totalLength = 0;
        for (long[] longs : arrays) {
            totalLength += longs.length;
        }
        long[] newArray = new long[totalLength];
        int pointer = 0;
        for (long[] longs : arrays) {
            System.arraycopy(longs, 0, newArray, pointer, longs.length);
            pointer += longs.length;
        }
        return newArray;
    }

    public static <T> T[] combine(T[]... arrays) {
        int totalLength = 0;
        for (Object[] longs : arrays) {
            totalLength += longs.length;
        }
        Object[] newArray = new Object[totalLength];
        int pointer = 0;
        for (Object[] objects : arrays) {
            System.arraycopy(objects, 0, newArray, pointer, objects.length);
            pointer += objects.length;
        }
        return (T[]) newArray;
    }
}