Answer:
(Assuming Java)
public ArrayList diff(ArrayList list1, ArrayList list2) {
ArrayList<Integer> union = new ArrayList<>();
for (int element : list1) {
union.add(element);
}
for (int element : list2){
if (!union.contains(element)) {
union.add(element);
}
}
return union;
}
Explanation:
Create an ArrayList that has the union of list1 and list2.
First for loop copies all elements into the union array list.
Second for loop adds all elements that are not yet in the union arraylist to the union arraylist.
(Keep in mind that I assume that you mean a mathematical union, so no duplicates. If this is not what you mean, remove the if statement in the second for loop)