Have two methods, main and twoTimes that takes in a single parameter (ArrayList) but returns the said ArrayList doubled and in order.
I have twoTimes repeating the variables within the parameters but it's coming out (1,5,3,7,1,5,3,7) instead of (1,1,5,5,3,3,7,7).
import java.lang.reflect.Array;
import java.util.ArrayList;
class Main {
public static void main(String[] args) {
ArrayList<Integer> nums = new ArrayList<>();
nums.add(1);
nums.add(5);
nums.add(3);
nums.add(7);
twoTimes(nums);
}
public static ArrayList<Integer> twoTimes(ArrayList nums) {
ArrayList<Integer> newNems = new ArrayList<>(nums);
newNems.addAll(nums);
System.out.println(newNems);
return newNems;
}
}