0

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..........

Edited by bharath54321: n/a

3
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by bharath54321
0

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;

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.