public class Reverse {
public static void main(String[] args) {
String [] simpsons = {"Homer", "Flanders", "Apu"};
reverse(simpsons);
System.out.println(simpsons[0] + " " + simpsons[1] + " "
+ " " + simpsons[2]);
} //End main
public static void reverse(String[] list)
{
String[] temp = new String[list.length];
for (int i =0; i<list.length; i++)
{
temp[i] = list[list.length-i-1];
}
//System.arraycopy(temp, 0 , list, 0, list.length);
list = temp;;
}
}
I'm just getting started in Java, and this problem confused me. As you can see, I've solved the problem with the commented out arraycopy method. I'm simply confused as to why the list = temp still returns the original, non-reversed array. I believe I understand conceptually that references are just locations in memory, but doesn't list = temp assign the passed in array to the memory location of temp, AKA the reversed array?