Here you can find the source of mergeSortedAaary(int[] a, int[] b)
static Integer[] mergeSortedAaary(int[] a, int[] b)
//package com.java2s; //License from project: Apache License public class Main { static Integer[] mergeSortedAaary(int[] a, int[] b) { int aL = a.length; int bL = b.length; Integer[] c = new Integer[aL + bL]; int countA = 0; int countB = 0; int countC = 0; while (countA < aL || countB < bL) { if (countA < aL && countB < bL && a[countA] < b[countB]) { c[countC] = a[countA];/*from ww w .ja va 2 s . com*/ countA++; countC++; } else if (countA < aL && countB < bL && b[countB] < a[countA]) { c[countC] = b[countB]; countB++; countC++; } else if (countA < aL && countB < bL && b[countB] == a[countA]) { c[countC] = a[countA]; countA++; countC++; c[countC] = b[countB]; countB++; countC++; } else if (countA == aL) { c[countC] = b[countB]; countB++; countC++; } else if (countB == bL) { c[countC] = a[countA]; countA++; countC++; } } return c; } }