Here we combine two int arrays of any size.
Example
int[] a = {1,2,3,4};
int[] b = {5,6,7};
Output
{1,2,3,4,5,6,7}
run:
[1, 2, 3, 4, 5, 6, 7]
BUILD SUCCESSFUL (total time: 0 seconds)
package codejam_class.fortesting;import java.util.ArrayList;/** * * @author RAYMARTHINKPAD */public class CombiningArray { public ArrayList<Integer> combineArray(int[] a, int[] b) { ArrayList<Integer> al1 = this.convertIntArrArrayList(a); ArrayList<Integer> al2 = this.convertIntArrArrayList(b); ArrayList<Integer> both = new ArrayList(); both.addAll(al1); both.addAll(al2); return both; } public ArrayList<Integer> convertIntArrArrayList(int[] a) { ArrayList al = new ArrayList(); for (int i = 0; i < a.length; i++) { al.add(a[i]); } return al; }}
package codejam_class.fortesting;/** * * @author RAYMARTHINKPAD */public class CombiningArrayMain { public static void main(String[] args) { CombiningArray ca = new CombiningArray(); int[] a = {1, 2, 3, 4}; int[] b = {5, 6, 7}; System.out.println(ca.combineArray(a, b)); }}