集合中存储的是对象么

集合中存储的是对象么
集合中存储的实际上是对象的引用

import java. util.ArrayList ;
import java. util.List ;

class Apple{
    private String color ;
    private String type ;
    public Apple (String color, String type) {
         super();
         this.color = color;
         this.type = type;
    }
}

public class Main {
    public static void main (String[] args) {
        Apple apple1 = new Apple("red" ,"type1");
        Apple apple2 = new Apple("green" ,"type2");
        List <Apple> apples = new ArrayList<Apple>(4 );
        apples .add( apple1);
        apples .add( apple2);
    }
}






原文地址:https://www.cnblogs.com/ZhangJinkun/p/4531636.html