package Dec2016; import java.util.ArrayList; import java.util.List; public class Ques1228 { public static void main(String[] arg){ Student stu01 = new Student("001"); Student stu02 = new Student("001 "); // stu02中001後面有個空格 List<Student> students = new ArrayList<Student>(); students.add(stu01); students.add(stu02); System.out.println("students是否包含001學號:"+students.contains(stu01)); System.out.println("students是否包含002學號:"+students.contains(stu02)); } } 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; return stuId.equalsIgnoreCase(stu.getStuId().trim()); } return false; } }
今日問題:
請問主程序輸出結果是什麼?(點擊以下“【Java每日一題】20161228”查看20161227問題解析)
題目原發布於公眾號、簡書:【Java每日一題】20161228,【Java每日一題】20161228
注:weknow團隊近期開通並認證了分答,歡迎大家收聽,有問題也歡迎到分答來咨詢哦,回見您!!