数组拷贝问题,实际上是指针指向发生变化

public class Test{
    public static void main(String args[]){
        int[] a= {1,2,3};
        int[] b={4,5,6};
        //输出两个数组
        System.out.print("原数组a:");
        for(int i : a)
        System.out.print(i+" ");
        System.out.println();
        System.out.print("原数组b: ");
        for(int i : b)
        System.out.print(i+" ");
        System.out.println();
        //拷贝数组
        a=b;
        //输出拷贝后的两个数组
        System.out.print("--------数组拷贝---------\n数组a:");
        for(int i : a)
        System.out.print(i+" ");
        System.out.println();
        System.out.print("数组b: ");
        for(int i : b)
        System.out.print(i+" ");
        System.out.println();
        System.out.println("改变数组a[0]的值==9");
        //改变数组a的值
        a[0]=9;
        System.out.println("a[0] : "+a[0]);
        System.out.println("b[0] : "+b[0]);
    }
}
/*
    C:\>javac Test.java
    
    C:\>java Test
    原数组a:1 2 3
    原数组b: 4 5 6
    --------数组拷贝---------
    数组a:4 5 6
    数组b: 4 5 6
    改变数组a[0]的值==9
    a[0] : 9
    b[0] : 9

*/
原文地址:https://www.cnblogs.com/laoquans/p/2963351.html