Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JAVA: Provide a static method void append(ArrayList<T> a, ArrayList<T> b) that a

ID: 663700 • Letter: J

Question

JAVA: Provide a static method void append(ArrayList<T> a, ArrayList<T> b) that appends the elements of b to a.

HELP!

This is what I have:

import java.util.ArrayList;
public class ArrayListA
{
ArrayList<Sting> a = new ArrayList <string>();
a.add("apple");.add("banana");
b.add("carrot");
b.add("zucchini");
System.out.print("A Contents" + printMyList(a));
append(a, b);
System.out.println("A append" + printMyList(a));
}
public static printMyList(Array<String> myList)
{
String str = "";
for (String c : myList)
{ str = str + c + "";}
str = str + " ";
return str;
}
}

public static <T> void append(ArrayList<T> f, ArrayList<T> g)
{
for (T temp = g)
{ f.add(temp); }
}

Explanation / Answer

I am using two approaches here one with Iterator and one without Iterators

With Iterator

Without Iterator