Question: Write a method public static ArrayList merge(ArrayList a, ArrayList b) that merges two array lists, alternating elements from both array lists. If one array list
Write a method public static ArrayList merge(ArrayList a, ArrayList b) that merges two array lists, alternating elements from both array lists. If one array list is shorter than the other, then alternate as long as you can and then append the remaining elements from the longer array list.
And here is my code. In java
import java.util.ArrayList; import java.util.Arrays;
public class Num4 { public static void main(String[] args) { int []a = {1,3,5,7}; int []b = {2,4,6,8}; System.out.println(merge(a, b));
} public static ArrayList merge(ArrayList a, ArrayList b) { ArrayList comb = new ArrayList[a.size() + b.size()]; int j = 0; int k = 0; int l = 0; int max = Math.max(a.size(),b.size()); for (int i = 0; i

Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
