Assuming that the Given array is instantiated as follows: int[] given = {1, 2, 3, 4, 5};
These methods should change the array and show the print results.
public int[] change(int[] given) {
out.println(Arrays.toString(given)); //before-changes
whatIsGoingOn(given); //make changes
out.println(Arrays.toString(given));//after changes
return given; //return the supposedly changed array
}
//Make changes:
public void whatIsGoingOn(int[] given) {
given = new int[5];
given[0] = 200;
}
I BELIVE THE PROBLEM to be with the void method, overriding the original values of the int[] given but the new initialization and declarations never make it out.
I Would expect the array to be:
{200, 0, 0, 0, 0};
But Java prints out:
{1, 2, 3, 4, 5}
{1, 2, 3, 4, 5}
But in the case where I returned a newly changed array in the whatIsGoingOnMethod, I get my wanted results:
{1, 2, 3, 4, 5}
{200, 0, 0, 0, 0}
If the void method just does something and its not really being "applied" as I would like to expect. I'd appreciate an illuminating explanation for this.
This Question is ALREADY ANSWERED THANKS!!! I need to freeze it.