首页 > 其他 > 详细

集合中存储的是对象么

时间:2015-05-26 21:14:59      阅读:234      评论:0      收藏:0      [点我收藏+]
集合中存储的是对象么
集合中存储的实际上是对象的引用

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

技术分享





集合中存储的是对象么

原文:http://www.cnblogs.com/ZhangJinkun/p/4531636.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!