首页 > 其他 > 详细

list集合接口

时间:2016-08-26 18:34:44      阅读:218      评论:0      收藏:0      [点我收藏+]
import java.util.ArrayList;
import java.util.List;

class Phone {
    private String brand;
    private double price;
    public Phone(String brand, double price) {
        this.brand = brand;
        this.price = price;
    }
    @Override
    public boolean equals(Object obj) {
        if(this == obj){
            return true;
        }
        if(obj == null){
            return false;
        }
        if(! (obj instanceof Phone)){
            return false;
        }
        Phone phone = (Phone) obj;
        return this.brand.equals(phone.brand) && this.price==phone.price;
    }
    @Override
    public String toString() {
        return brand + price;
    }
}
public class Hello{
    public static void main(String args[]) throws Exception{
        List<Phone> list = new ArrayList<Phone>();
        list.add(new Phone("红米",399));
        list.add(new Phone("黑米",499));
        System.out.println(list.get(1));
        
    }
}

 

list集合接口

原文:http://www.cnblogs.com/cyxxzjp/p/5811256.html

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