I have a Vector<int[][]>
and when I give it a clone of my int[][]
array and than change something in my int[][]
array and call int[][] = Vector.get(0)
the array doesn't revert back to the value it should.
How can I get my int[][] to become the value of Vector.get(0)?
import java.util.Vector;
public class ArrayFromVectorProblem {
public static void main(String[] args){
int[][] myArray = {{0,0,1, 0, 0}, {0,0,2,0,0}};
Vector<int[][]> myVector = new Vector<int[][]>();
myVector.add(myArray.clone());
myArray[1][2] = 5;
//should print 5, and prints 5
System.out.println("MyArray[1][2]: " + myArray[1][2]);
myArray = myVector.get(0);
//should print 2, and prints 5
System.out.println("MyArray[1][2] 2nd try: " + myArray[1][2]);
}
}
this is my output:
MyArray[1][2]: 5
MyArray[1][2] 2nd try: 5