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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started