package cn.itcast.collection;
public class Student {
private String name;
private int age;
public Student(String name,int age){
this.age = age;
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
//该对象的字符串表示形式(若不写该方法则输出的是一个地址)
public String toString(){
return "Student " + name +"..."+ age;
}
==============================================
//去除new对象的重复
public boolean equals(Object obj){
if(obj == null)
return false;
if( this == obj)
return true;
if(obj instanceof Student){
Student s = (Student)obj;
//比姓名和年龄,相同返回真,不同返回假 this s
return this.name.equals(s.name) && this.age == s.age;
}
return false;
}
}
就是一个外部的学生类,然后===========下面的这些东西,我只知道是用来取出new出来一个对象这中重复的!但是还是不太理解!能不能有人帮我注释一下!谢啦:)
. |
|