我不是程序猿,请叫我攻城狮Java每日一题技术干货

Java每日一题20170220

2017-02-20  本文已影响24人  weknow

因简书改版后无法添加扩展链接,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<Student> list = new ArrayList<Student>();
        list.add(new Student("001"));
        
        Map<Student, Object> map = new HashMap<Student, Object>();
        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;
    } 
    
}

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

注:weknow团队近期开通并认证了分答,欢迎大家收听,有问题也欢迎到分答来咨询哦,回见您!!

748537-0a2c0f3ca15d5dc5.png
上一篇下一篇

猜你喜欢

热点阅读