Everything in Java are passed-by value...对于Array(它只不过是一个对象),数组引用是通过值传递的。(就像通过值传递对象引用一样)。
当您将数组传递给其他方法时,实际上复制了对该数组的引用。通过该引用对数组内容的任何更改都将影响原始数组。
但是,将引用更改为指向新数组并不会更改原始方法中现有的引用。
看这个帖子.。
参见下面的工作示例:-public static void changeContent(int[] arr) {
// If we change the content of arr.
arr[0] = 10; // Will change the content of array in main()}public static void changeRef(int[] arr) {
// If we change the reference
arr = new int[2]; // Will not change the array in main()
arr[0] = 15;}public static void main(String[] args) {
int [] arr = new int[2];
arr[0] = 4;
arr[1] = 5;
changeContent(arr);
System.out.println(arr[0]); // Will print 10..
changeRef(arr);
System.out.println(arr[0]); // Will still print 10..
// Change the reference doesn't reflect change here..}