- public class Test {
- public static void main(String[] args) {
- Point[] p1=new Point[]{new Point(1,1),new Point(2,2),new Point(3,3)};
- Point[] p2=new Point[3];
- System.arraycopy(p1, 0, p2, 0, p1.length);
- for(int i=0;i<p1.length;i++)
- System.out.println("x:"+p2[i].x+" y:"+p2[i].y);
- p1[1].x=4;
- p1[1].y=4;
- System.out.println("x:"+p2[1].x+" y:"+p2[1].y);
- }
- }
- class Point
- {
- int x,y;
- Point(int x,int y)
- {
- this.x=x;
- this.y=y;
- }
- }
复制代码
为什么结果会是x:4 y:4
我明明改的是p1的数据啊 |