从ArrayList中删除对象后如何返回?

nnn*_*nnn 2 java

我想这样做,但是我不确定分配的参考温度是否在删除后仍然有效.

public Box removeBox(int index)
{
Box temp=getBoxes().get(index);//ArrayList.get
getBoxes().remove(index);
return temp;
}
Run Code Online (Sandbox Code Playgroud)

Lou*_*man 9

这很好,虽然return getBoxes().remove(index)可以在一行中做同样的事情.