I’ve created this just to test things outside my main program. I got this error in my main program and am attempting to fix it now. I’m not sure if this is the best way to go about this, however I have an ArrayList and wish to be able to either replace the values in it to something that wont ever be possible to be hit. Or remove it from the array without affecting the length and the other values. So poisition 0 is still 0. Position 4 is still position 4 regardles if possition 2 has been removed. Here is my current code.
import java.util.ArrayList;
import java.awt.geom.Rectangle2D;
public class Main
{
public static void Main(String [] args)
{
ArrayList xcoords = (new Objects()).xco();
for( int x = 0 ; x < xcoords.size() ; x++ )
{
System.out.println(xcoords.get(x));
}
System.out.println("Start Replace");
xcoords.set(0,10,15,34,54);
System.out.println("End replace");
for( int x = 0 ; x < xcoords.size() ; x++ )
{
System.out.println(xcoords.get(x));
}
}
}
And my objects class
import java.util.ArrayList;
import java.awt.geom.Rectangle2D;
public class Objects
{
ArrayList<Integer> xco()
{
ArrayList rectangles = new ArrayList();
rectangles.add((new Rectangle2D.Double(5,10,20,100) ) );
rectangles.add((new Rectangle2D.Double(4555,1566,20,100) ) );
rectangles.add((new Rectangle2D.Double(73,45,20,100) ) );
rectangles.add((new Rectangle2D.Double(1463,98623,20,100) ) );
return rectangles;
}
}
Error

So, is there an easior way using ArrayLists to get the desiered function and how would I go about ‘setting’ the value in the arraylist.
Thanks, Kyle.
ArrayList#settakes to arguments, an index and the object that you want to store at that index position. In your code I count five parameters.If you want to replace the first rectangle in the list with a new one, then it would be: