I have 3 ArrayLists that I need to be able to clear between loops. They store a few values for my method to use in calculations, but I need the ArrayLists that store them empty again so that I can put new values in and the method only consider the new values. I have tried the ArrayList.clear() but it makes the method
return this:Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0. I tried to check them against the original list with the removeAll method, but it didn't work either. Help is appreciated.
return this:Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0. I tried to check them against the original list with the removeAll method, but it didn't work either. Help is appreciated.
public static double getZMM(double[][] A, ArrayList<Double> b, ArrayList<Double> c, ArrayList<Double> d){ int e = 0; double volume = 0; double xmax = 0; double xmin = 0; double ymax = 0; double ymin = 0; double zmax = 0; double zmin = 0; double total = 0; double stepSize = 2; double[][] a = A; ArrayList<Double> x = new ArrayList(); ArrayList<Double> y = new ArrayList(); ArrayList<Double> z = new ArrayList(); while( e < a.length - 1){ for(int i = 0; i < a.length - 1; i++){ if(a[i][2] < stepSize & a[i][2] > stepSize - 2){ x.add(a[i][0]); // I need to clear these y.add(a[i][1]);// z.add(a[i][2]);// } } xmax = x.get(0); for (int r = 1; r < x.size(); r++){ if (x.get(r) > xmax) xmax = z.get(r); } xmin = x.get(0); for (int w = 1; w < x.size(); w++){ if (x.get(w) < xmin) xmin = x.get(w); } ymax = y.get(0); for (int s = 1; s < y.size(); s++){ if (y.get(s) > ymax) ymax = y.get(s); } ymin = y.get(0); for (int v = 1; v < y.size(); v++){ if (y.get(v) < ymin) ymin = y.get(v); } zmax = z.get(0); for (int h = 1; h < z.size(); h++){ if (z.get(h) > zmax) zmax = z.get(h); } zmin = z.get(0); for (int j = 1; j < z.size(); j++){ if (z.get(j) < zmin) zmin = z.get(j); } double zDistance = eq(zmax,zmin,ymax,ymin,xmax,xmin); total = ( Math.PI * (Math.pow(((xmax+ymax)/2),2) * zDistance)); volume = total+=total; e++; stepSize+=stepSize; } return volume; }