码迷,mamicode.com
首页 > 其他好文 > 详细

list集合接口

时间:2016-08-26 18:36:35      阅读:143      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!