this is from an earlier reply
create an array[4] of arrayLists
iterate POLYGONS, for each POINTS (there are 25 of them), add it to array[pnt.getID()-1]
you have 4 arrayLists in an array - arrayList[0],arrayList[1],arrayList[2],arrayList[3]
now iterate POLYGON
for (POINTS pnt : POLYGON)
and all you do is
arrayList[pnt.getID()-1].add(pnt)
now all your polygon points are in their own separate arraylist
and the rest is simple, really simple