Question: java please Task 2.5 Complete the method called myUnion() in Main.java. The method should return a new String[] array containing the first n consecutive elements

java please  java please Task 2.5 Complete the method called myUnion() in Main.java.
The method should return a new String[] array containing the first n

Task 2.5 Complete the method called myUnion() in Main.java. The method should return a new String[] array containing the first n consecutive elements that are equal between the array and ArrayList, not including nulls. Meaning, if the array and ArrayList are ["a", "b", "c", null] and ["a", "b", "c", null} respectively, the method should return ("a", "b", "C"). Another example: if the array and ArrayList are ("a", "b", "c", null, null] and ["a", "b", "d", "c", null} respectively, the method should return ("a", "b"] . One final example: if the array and ArrayList are ["a", "z", "C") and {"a", "b", "c"} respectively, the method should return ("a"] . An empty array should be returned if there is no overlap. The returned array should be of size n. You can assume that both the array and ArrayList are arranged with all of the null values at the end. Be careful of accessing an out-of-bounds index or calling String.equals() on null values! Run it! Mainava import java.util.ArrayList; 01 A2 A public class Main { public static String() myUnion(String[] a, ArrayList 1) { return newArray: > public static void main(String[] args) { // write some tests here

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!