Java每日一题20170220

因改版后无法添加扩展链接,20170217问题解析请到公众号查看,问题解析在公众号首发,公众号ID:weknow619。

package Feb2017;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Ques0220 {

    public static void main(String[] args) {
        List list = new ArrayList();
        list.add(new Student("001"));
        
        Map map = new HashMap();
        map.put(new Student("001"), new Object());
        
        System.out.println("list是否包含001:"+list.contains(new Student("001")));
        System.out.println("map是否包含001:"+map.containsKey(new Student("001")));
    }
}

class Student{
    private String stuId;
    
    public Student(String stuId) {
        super();
        this.stuId = stuId;
    }

    public String getStuId() {
        return stuId;
    }

    public void setStuId(String stuId) {
        this.stuId = stuId;
    }
    
    @Override
    public boolean equals(Object obj) {
        if(obj instanceof Student){
            Student stu = (Student) obj;
            if(stu.getStuId() == null || stuId == null){
                return false;
            }else{
                return stuId.equalsIgnoreCase(stu.getStuId());
            }
        }
        return false;
    } 
    
}

今日问题:
请问主程序输出结果是什么?

你可能感兴趣的:(Java每日一题20170220)