开发者

Final arraylist declaration

When I declared final arraylist(), then can I perform insert,search and update operatio开发者_开发问答n in that arraylist or not.


Final means that the variable pointing to the arraylist can't change. But that does not mean that you can not call any method of the object, so you can perform insert, search and any other operation to the object


If a list is declared final as follows:

public final List myList = new ArrayList();

there's nothing to stop modifications to the list:

myList.add("value");

However, the following would not be possible:

myList = new ArrayList();
myList = someOtherList;


If you're talking about Java's ArrayList, then, yes you can. Final means just that you can't change which ArrayList instance your variable refers to.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜