How to obtain the index of one Instance in a List?
class Points {
int x, y;
Point(this.x, this.y);
}
void main() {
var pts = new List();
int Lx;
int Ly;
Points pt = new Points(25,55); // new instance
pts.add(pt);
int index = pts.indexOf(25); // Problem !!! How to obtain the index in a list of instances ?
if (index != -1 ){
Lx = lp1.elementAt(index).x;
Ly = lp1.elementAt(index).y;
print('X=$Lx Y=$Ly');
}
pts.indexOf(25)
return? The first element wherex
ory
equals25
? – Resumptionmap.values
but looking up a Point by x value would be much faster (Gunter's answer is O(n) whereas a map will find the Point in O(log n) time). – Fortis