Java Array Merge mergeByArray(int[] a, int[] b)

Here you can find the source of mergeByArray(int[] a, int[] b)

Description

merge By Array

License

Apache License

Declaration

private static int[] mergeByArray(int[] a, int[] b) 

Method Source Code

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

public class Main {

    private static int[] mergeByArray(int[] a, int[] b) {
        int[] c = new int[a.length + b.length];

        int i = 0, j = 0, k = 0;

        while (i < a.length && j < b.length) {
            if (a[i] <= b[j]) {
                if (a[i] == b[j]) {
                    j++;/*from w  w w.ja  va 2  s  .c  om*/
                } else {
                    c[k] = a[i];
                    i++;
                    k++;
                }
            } else {
                c[k] = b[j];
                j++;
                k++;
            }
        }
        while (i < a.length) {
            c[k] = a[i];
            k++;
            i++;
        }
        while (j < b.length) {
            c[k] = b[j];
            j++;
            k++;
        }
        return c;
    }
}

Related

  1. mergeArrays(String[] inputArray1, String[] inputArray2)
  2. mergeArrays(T[] items, T[]... added)
  3. mergeArrays(T[] lhs, T[] rhs)
  4. MergeArrays(T[]... arrs)
  5. mergeArrayToString(final String[] array)
  6. mergeByteArraies(byte[] array1, byte[] array2)
  7. mergeByteArrays(byte[] array1, byte[] array2)
  8. mergeByteArrays(byte[] one, byte[] two)
  9. mergeBytearrays(byte[] ret, byte[] header, byte[] body)