Properly removing an Integer from a List

前端 未结 8 1846
面向向阳花
面向向阳花 2020-11-22 03:57

Here\'s a nice pitfall I just encountered. Consider a list of integers:

List list = new ArrayList();
list.add(5);
list.add(6);         


        
8条回答
  •  爱一瞬间的悲伤
    2020-11-22 04:53

    list.remove(4) is an exact match of list.remove(int index), so it will be called. If you want to call list.remove(Object) do the following: list.remove((Integer)4).

提交回复
热议问题