Create a method called mergeTwoArrayLists
which takes in two ArrayLists as
inputs, l1
and l2
. The lists can contain both positive and negative
integers. The method should collect the positive elements from the lists into a
new ArrayList and return it.
Here’s the starter code with an example in the main
method:
import java.util.ArrayList;
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
ArrayList<Integer> l1 = new ArrayList<Integer>(Arrays.asList(-5, 4, 13, -23, -65, 5, -2));
ArrayList<Integer> l2 = new ArrayList<Integer>(Arrays.asList(7, 3, -3, -6, 5, 10, 8));
ArrayList<Integer> res = mergeTwoArrayLists(l1, l2); // [4, 13, 5, 7, 3, 5, 10, 8]
System.out.println(res);
}
public static ArrayList<Integer> mergeTwoArrayLists(ArrayList<Integer> l1, ArrayList<Integer> l2) {
// your code here
}
}