我想檢查對象球是否包含在ArrayList
或不。但每次我經歷循環時,結果都會給出錯誤的答案。但我已經把對象球放在了ArrayList
。不能這樣做: - someList.contains(new Point(x,y))
識別arraylist中的自定義對象
public class zbc {
ArrayList<Balls> balls;
public boolean somRandomFunction() {
if (balls.contains(new Ball(i, j, k))) {
System.out.println("-----------------true------------------");
break;
}
}
}
public class Ball {
private int row, col;
// this is actually just a integer value used
// by game to draw various distinct color
private int color;
public Ball(int row, int col, int color) {
this.row = row;
this.col = col;
this.color = color;
}
public int row() {
return row;
}
public int col() {
return col;
}
public int color() {
return color;
}
}
沒有幫助MCH我得到它的另一種方式, 如果(ball.get(i,j)> 0){(Ball ball:balls){ if flag = false; 休息; } } –