java中list的remove()问题

2025-02-26 05:50:17
推荐回答(1个)
回答1:

这是linkedlist的官方API:http://docs.oracle.com/javase/7/docs/api/java/util/LinkedList.html

E remove()
Retrieves and removes the head (first element) of this list.

E remove(int index)
Removes the element at the specified position in this list.

boolean remove(Object o)
Removes the first occurrence of the specified element from this list, if it is present.

上面写了remove有3种用法,但是你的xfood 是String[], 如果你定义 LinkedList的话这个就可以用,
把 String[] xfood={"bread"}; 改成 String xfood="bread";

bread 应该就会被删除