This is in java. I tried looking for / googling for an answer to this question here and couldn't find a sufficient answer, so I apologize if this is a duplicate. I am confused as to the rules behind methods changing the parameter that you input. For example, consider the following example
public static void messWithArray(int[] array)
{
array[0] = 100;
array[0] += 5;
// make new array
int[] array2 = new int[10];
for(int i = 0; i < 10; i++)
{
array2[i] = 5+i;
}
array = array2
}
public static void main(String[] args)
{
int[] a = new int[10]
for(int i=0; i < 10; i++)
{
a[i] = i*10
}
messWithArray(a);
System.out.println(a[0]);
System.out.println(a[1]);
This prints that a[0] is 105 and a[1] is 10, so making array[0] equal to 100 and adding 5 to it in the messWithArray method had an effect. However, assigning array = array2 didn't do anything (since a[1] is 10). I also tried messing with an int but couldn't get it to work.
I would like to know more specifically/clearly the logic behind whether or not a method will change attributes of an array.