集合中存储的是对象么

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

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);
    }
}






posted @ 2015-05-26 20:09  外禅内定,程序人生  阅读(221)  评论(0编辑  收藏  举报