Java每日一题20170220

作者: weknow | 来源:发表于2017-02-20 08:48 被阅读24次

    因简书改版后无法添加扩展链接,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

    相关文章

      网友评论

        本文标题:Java每日一题20170220

        本文链接:https://www.haomeiwen.com/subject/jfalwttx.html