package com.yuan.List;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class list {
public static void main(String[] args) {
List list = new ArrayList<>();
list.add(new Student(1, "1"));
list.add(new Student(2, "2"));
list.add(new Student(3, "3"));
list.add(new Student(3, "3"));
List newlist = new ArrayList<>();
for (Object object : list) {
if(!newlist.contains(object)) {
newlist.add(object);
}
}
System.out.println(list.size());
System.out.println(newlist.size());
}
}
class Student{
private int id;
private String name;
public Student() {
// TODO Auto-generated constructor stub
}
public Student(int id, String name) {
super();
this.id = id;
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return "student [id=" + id + ", name=" + name + "]";
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Student other = (Student) obj;
if (id != other.id)
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
return true;
}
}