字符串的深层复制

package base.taxt;
import java.util.Arrays;
class Clothes{
    String color;
    char size;
    Clothes(String color,char size ){
        this.color=color;
        this.size = size;
    }
}
public class array {
    public static void main(String[] args) {
        Clothes[] frist = {new Clothes("red", 'M'), new Clothes("blue", 'S')};
        Clothes[] second = {new Clothes("blue", 'S')};
        Clothes[] third = new Clothes[frist.length];
        for (int i = 0; i < frist.length; i++) {
            //这个是最基础的打印方法.
       Clothes copy = new Clothes(frist[i].color,frist[i].size);
       third[i]=copy;
        }
        //打印数组中的东西的方法
        //toString不支持String
        System.out.println(second[0].color);
        System.out.println(third[0].color);
        System.out.println(Arrays.toString(third));
        //输出的是地址

    }
}


版权声明:本文为m0_54662917原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。