I’m trying to delete all the duplicate points within two array lists. Each list is created by finding which country links to which country, if they link then it creates a new point in both arrays at the same time.
The idea is so that I can loop though the size of both arrays (Or size of one) and draw lines between the points.
Problem at the moment is that it’s not deleting the points or it deletes them all.
I have the following Arrays
//Different values of course.
Array1 = [Point[1,5]],[Point[1,5]],[Point[1,5]][Point[1,5]]
Array2 = [Point[1,5]],[Point[1,5]],[Point[1,5]][Point[1,5]]
Here’s the code that deletes the duplicate arrays out:
private ArrayList<ArrayList<Point>> checkDuplicatePoints(ArrayList<Point> Array1, ArrayList<Point> Array2)
{
for(int index1 = 0; index1 < Array1.size(); index1++)
{
for(int index2 = 0; index2 < Array2.size(); index2++)
{
//So not the same position in the list.
if(index1 != index2)
{
if(
Array1.get(index1).x == Array2.get(index2).x &&
Array1.get(index1).y == Array2.get(index2).y
)
{
Array1.remove(index1);
Array2.remove(index2);
checkDuplicatePoints(Array1, Array2);
}
}
}
}
ArrayList<ArrayList<Point>> n2DPointArray = new ArrayList<ArrayList<Point>>();
n2DPointArray.add(Array1);
n2DPointArray.add(Array2);
return n2DPointArray;
}
As far as i underStand your problem may be you should look into these code and example
OUTPUT
[java.awt.Point[x=1,y=2], java.awt.Point[x=2,y=3], java.awt.Point[x=1,y=2], java.awt.Point[x=2,y=3], java.awt.Point[x=1,y=2], java.awt.Point[x=2,y=3]]
//after removing duplicate from arrayList1
[java.awt.Point[x=1,y=2], java.awt.Point[x=2,y=3]]
I hope this could help you or ..else be more specific to your problem and result you need out of your array list