如何獲取鏈接列表中的數據引用/索引?列表鏈接列表參考
例如如果我有這個鏈表
java.util.List<Polygon> triangles = new LinkedList<Polygon>();
polygon triangle, selectedTriangle;
Point startDrag,endDrag,midPoint;
....
triangles.add(new Polygon(xs, ys,3));
例如,如何將多邊形selectedTriangle設置爲與鏈接數組列表中現有三角形的一個相同?
編輯:
java.util.List<Polygon> triangles = new LinkedList<Polygon>();
polygon triangle, selectedtriangle;
....
triangles.add(new Polygon(xs, ys,3));
.....
public void mousePressed(MouseEvent e) {
....
startDrag = new Point(e.getX(), e.getY());
endDrag = startDrag;
for (Polygon p : triangles) {
if (p.contains(startDrag)) {//inside triangle
//I dont know how to set the selectedTriangle as the same with existing triangle
selectedTriangle = triangles.indexOf(p.contains(startDrag));
break; //
}
}
.....
}