Java Array Merge merge(int[]... arrs)

Here you can find the source of merge(int[]... arrs)

Description

merge

License

Open Source License

Declaration

public static int[] merge(int[]... arrs) 

Method Source Code

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

public class Main {

    public static int[] merge(int[]... arrs) {
        int[] result = new int[0];
        if (arrs != null) {
            int count = 0;
            for (int i = 0; i < arrs.length; i++) {
                count += arrs[i].length;
            }//ww  w .ja v a  2 s . c o m
            result = new int[count];
            int arg;
            int k = 0;
            for (int i = 0; i < arrs.length; i++) {
                if (arrs[i] == null) {
                    continue;
                }
                for (int j = 0; j < arrs[i].length; j++) {
                    arg = arrs[i][j];
                    result[k] = arg;
                    k++;
                }
            }
        }
        return result;
    }

    public static char[] merge(char[]... arrs) {
        char[] result = new char[0];
        if (arrs != null) {
            char count = 0;
            for (char i = 0; i < arrs.length; i++) {
                count += arrs[i].length;
            }
            result = new char[count];
            char arg;
            char k = 0;
            for (char i = 0; i < arrs.length; i++) {
                if (arrs[i] == null) {
                    continue;
                }
                for (char j = 0; j < arrs[i].length; j++) {
                    arg = arrs[i][j];
                    result[k] = arg;
                    k++;
                }
            }
        }
        return result;
    }

    public static byte[] merge(byte[]... arrs) {
        byte[] result = new byte[0];
        if (arrs != null) {
            byte count = 0;
            for (byte i = 0; i < arrs.length; i++) {
                count += arrs[i].length;
            }
            result = new byte[count];
            byte arg;
            byte k = 0;
            for (byte i = 0; i < arrs.length; i++) {
                if (arrs[i] == null) {
                    continue;
                }
                for (byte j = 0; j < arrs[i].length; j++) {
                    arg = arrs[i][j];
                    result[k] = arg;
                    k++;
                }
            }
        }
        return result;
    }

    public static Object[] merge(Object[]... arrs) {
        Object[] result = new Object[0];
        if (arrs != null) {
            int count = 0;
            for (int i = 0; i < arrs.length; i++) {
                count += arrs[i].length;
            }
            result = new Object[count];
            Object arg;
            int k = 0;
            for (int i = 0; i < arrs.length; i++) {
                if (arrs[i] == null) {
                    continue;
                }
                for (int j = 0; j < arrs[i].length; j++) {
                    arg = arrs[i][j];
                    result[k] = arg;
                    k++;
                }
            }
        }
        return result;
    }

    public static String[] merge(String[]... arrs) {
        String[] result = new String[0];
        if (arrs != null) {
            int count = 0;
            for (int i = 0; i < arrs.length; i++) {
                count += arrs[i].length;
            }
            result = new String[count];
            String arg;
            int k = 0;
            for (int i = 0; i < arrs.length; i++) {
                if (arrs[i] == null) {
                    continue;
                }
                for (int j = 0; j < arrs[i].length; j++) {
                    arg = arrs[i][j];
                    result[k] = arg;
                    k++;
                }
            }
        }
        return result;
    }
}

Related

  1. merge(int[] a, int[] b)
  2. merge(int[] a, int[] temp, int fromIndex, int toIndex)
  3. merge(int[] array, int i, int mid, int max)
  4. merge(int[] array1, int[] array2)
  5. merge(int[] x1, int[] x2)
  6. merge(long[] theArray, long[] workSpace, int lowPtr, int highPtr, int upperBound)
  7. merge(Object[][] array1, Object[][] array2)
  8. merge(String array[], String delimiter)
  9. merge(String[] array)