我的代码在使用ArrayList包含对象的测试时工作,但在arrayList空时发出以下错误:
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
Run Code Online (Sandbox Code Playgroud)
我错了什么?
获取Rectangle具有最小区域的返回具有最小区域的矩形或者null如果没有矩形.
import java.util.ArrayList;
public class RectangleList
{
ArrayList<Rectangle> list = new ArrayList<Rectangle>();
public RectangleList(ArrayList<Rectangle> theList)
{
list = theList;
}
/**
* Gets the Rectangle with the smallest area
*
* @return the rectangle with the smallest area or null if there are no
* rectangles
*
*/
public Rectangle smallestArea()
{
Rectangle currentsmallestRectangle = list.get(0);
for (int i = 0; i < list.size(); i++) …Run Code Online (Sandbox Code Playgroud)