package day03;
public class Cell {
int x;
private int y;
public Cell(int x,int y) {
this.x = x;
this.y = y;
}
public String toString() {
return "Cell[x=" + x + ",y=" + y + "]";
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (obj instanceof Cell) {
Cell c = (Cell) obj;
return this.x==c.x && this.y == c.y;
}
return false;
}
}
package day03;
import java.util.ArrayList;
import java.util.Collection;
public class CollectionDemo2 {
public static void main(String[] args) {
Collection c = new ArrayList();
Cell c1 = new Cell(1,2);
Cell c2 = new Cell(2,3);
Cell c3 = new Cell(3,4);
c.add(c1);
c.add(c2);
c.add(c3);
Cell c4 = new Cell(3,4);
if(c.contains(c4)) {
System.out.println("包含");
}else{
System.out.println("不包含");
}
}
}
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/f8283a56ea65cf83e56f77ac3a024111.png)