Rectangle Collision in ArrayList

the box class refers to any arbitrary rectangle shape, if that happens to be your car, then great.

The box a function just takes a class as a parameter in this case box, which will have 4 checkable sides. hence the 4 lines,

a box has four points, defined by (x,y),(x + width,y),(x+width,y+height),(x,y+height) in clockwise order, therefore you have to check all four points are inside the other rectangle.

Please note this is assuming no rotation is happening on the boxes.