public Point{
int x, y;
public Point(int x, int y){
int x = x;
int y = y;
// setters
// getters
// toString
}
}
ArrayList<Point> points = new ArrayList<>();
// add points by using points.add() then use this loop
ArrayList<ArrayList<Point>> A = new ArrayList<>();
for (int i = 0; i < 3; i++) {
A.add(points);
}
I have an arraylist of arraylists that each of them have the same points For example when you print this is the output
ArrayList<ArrayList<Point>> A = [[(0,10), (20,3), (2,5), (2,8)], [(0,10), (20,3), (2,5), (2,8)], [(0,10), (20,3), (2,5), (2,8)]]
I want to remove all the points that their x value is not equal to the index of the array list before printing
A.get(0) = [(0,10)]
A.get(1) = []
A.get(2) = [(2,5),(2,8)]
so the output should be
[[(0,10)], [], [(2,5), (2,8)]]
I tried to use remove method and for loop and other ways but they didn't work.
for(int i = 0; i < list.size();i++){
if(list.get(i).x != 0){
list.remove(i--);
}
}
Is there anyone who can help?