So I basically put some Integer objects in an ArrayList x, then put some in an ArrayList y, then did y.addAll(x), but it seems to be only adding the first one and leaving out all the rest! Isn't it supposed to add ALL? I looked it up on Oracle and they showed what seemed to be the EXACT SAME EXAMPLE yet mine is not working properly. Here is my code:
ArrayList<Integer> x = new ArrayList<Integer>();
Integer a = 1;
Integer b = 2;
Integer c = 3;
x.add(a);
x.add(b);
ArrayList< Integer> y = new ArrayList< Integer>();
y.addAll(x);
yet y seems to only have 1 in it and missing the 2 and the 3.
What am I doing wrong?
EDIT: Yes, sorry, I know I didn't actually add c to x yet, but even when I do, and then print y, I still get [1] instead of [1,2,3]. This is what I don't understand.
import java.util.ArrayList;
public class SumArrayList {
public static void main(String[] args) {
ArrayList<Integer> x = new ArrayList<Integer>();
Integer a = 1;
Integer b = 2;
Integer c = 3;
x.add(a);
x.add(b);
System.out.println(x);
//System.out.println(calculateSumArrayListHelper(x));
ArrayList<Integer> y = new ArrayList<Integer>();
y.addAll(x);
System.out.println(y);
//System.out.println(calculateSumArrayListHelper(y));
}
}
Here is a pic of what I see: http://postimg.org/image/ms0y68nnh/