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 mergesWrite 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

two array lists, alternating elements from both array lists. If one array

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!