you have to use nested loops. Other tools you may want to add to speed up efficiency are quadtrees or quadgrid, but thats not likely what you are looking for.
To begin, cosider the box you are checking, you now have to check that box to every other box.
If you have the one arraylist then you check one item against nothing by simply looping once.
ie
for (int i=0;i<boxes.size();i++){
//Box refers to a arbitrary Box class not attached with sketch
Box b = boxes.get(i);
// add any other code
}
now if you want the boxes to check other boxes you have to loop through all the boxes once again.
for (int i=0;i<boxes.size();i++){
//Box refers to a arbitrary Box class not attached with sketch
Box b = boxes.get(i);
// add any other code
for (int j=0;j<boxes.size();j++){
Box b1 = boxes.get(j);
// here you would add you check code;
boolean collide = b.compare(b1);
if(collide){
//do something
}
}}
the code to check collision should be fairly simple.
you want to know if any of the four bounding points are overlapping with any of the other squares lines.
ie
boolean compare(Box a){
return x > a.x && x < a.x + a.width && y > a.y && y < y + y.height||
x + width > a.x && x + width < a.x + a.width && y > a.y && y < y + y.height||
x + width > a.x && x + width < a.x + a.width && y + height > a.y && y + height< y + y.height||
x > a.x && x < a.x + a.width && y + height > a.y && y + height< y + y.height||
}
I think that should be it.
or you can try line line collisions which are a little bit more complex but will also do the job.
in general I would recommend reading through this blog post.