Could anyone please tell me how to Delete two Dimensional array Which i created early or Delete the contents of from specified index and i want to insert some other values in the same index..........

Recommended Answers

All 4 Replies

You can't explicitly "delete" a whole array in Java. Just like any other Java Object it will be thrown away ("garbage collected") when you have finished with it. Java knows you have finished with it when you no longer have any variables that refer to that array.

int[][] myArray = new int[2][3]; // creates a 2x3 array, and sets the variable  myArray to refer to it.
myArray = new int[2][4]; // myArray now refers to this new array. There are no references left to the old array, so it will be garbage collected

You can change or overwrite the value in any index of your array whenever you want, the syntax is the same as when you put a value in the first time. myArray[1][2] = someNewValue;

hard to speak about GC in (you & me) form and his form

advice:

//if you declare some Array (hint by JamesCherrill)
int[][] myArray = new int[2][3];
//then complete delete is crate new Object again
myArray = new int[2][3];

nothing else

Thank so much its working thanks

Thank so much its working thanks a lot............

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.