[Java] ArrayList element operation issue
Go to solution
Solved by highonquack,
Try this
ArrayList<int[]> x = new ArrayList<int[]>(); x.add(new int[] { 0, 0 }); // breakpoint 1 int[] y = new int[2]; y[0] = x.get(0)[0]; y[1] = x.get(0)[1]; // breakpoint 2
Objects are passed by reference in Java. So when you set y equal to the first array in the list, it passed you a pointer/reference to the array that was inside of the ArrayList.

Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now