What is wrong in this code?
Hello,
I have a ArrayList called "Storage" which contains String elements and two other ArrayLists , "DrawPointsX and DrawPointsY" which contain integer elements. All the ArrayList are of the same size and each element has a corresponding drawing points in both DrawPointsX and DrawPointsY. Eg, String element "Josy Wales" with index - Storage.get(b)[c] will have corresponding x-axis point in DrawPointsX.get(b)[c] and the same for DrawPointsY.
I planned to implement a method which checks when a string element first occur in the ArrayList "Storage" and how long it takes to occur again.
If it occur the first time and takes time longer than a given threshold to occur again, then I will delete in the "Storage" where ever this element is found and also delete their corresponding index in DrawPointsX and DrawPointsY.
If it occurs just once and if after a given time threshold (iteration) it does not occur, the element will be deleted with the corresponding drawing points.
Below is my method, which gives an IndexOutOfBoundsException. My question is, is anything wrong in this code?
publicvoid DrawPoints(){
System.out.println("DrawPoints()");
for(int a = 0; a < Storage.size(); a++){
for(int b = 0; b < Storage.get(a).length; b++)
for(int c = a+1; c < Storage.size(); c++){
for (int d = 0; d < Storage.get(c).length; d++)
if(Storage.get(a)[b].compareTo(Storage.get(c)[d])== 0){
if(Math.abs(c - a) > threshold){
//remove the element where ever it is found in the "Storage" and the Drawing Points in DrawPointsX and DrawPointsY
for(int r = 0; r < Storage.size(); r++){
for (int s = 0; s < Storage.get(r).length; s++){
if(Storage.get(r)[s].compareTo(Storage.get(a)[b]) == 0){
Storage.remove(Storage.get(r)[s]);
DrawPointsX.remove(DrawPointsX.get(r)[s]);
DrawPointsY.remove(DrawPointsY.get(r)[s]);
}
}
}
}
}
else
if (Storage.get(a)[b].compareTo(Storage.get(c)[d])!= 0){
//counter is the same as the size of the ArrayList
if(Math.abs(counter - a ) > threshold){
Storage.remove(Storage.get(a)[b]);
DrawPointsX.remove(DrawPointsX.get(a)[b]);
DrawPointsY.remove(DrawPointsY.get(a)[b]);
}
}
}
}
}
Thanks,
Jona_T

