我需要帮助这个java.我创建了一个灯泡ArrayList,我试图用另一个灯泡替换特定索引的灯泡.因此,使用以下标题,我该如何处理?
public void replaceBulb(int index, Bulbs theBulb) {
}
And*_*ler 117
您可以使用ArrayList的set方法替换特定位置的项目,如下所示:
list.set( your_index, your_item );
但是元素应该出现在你在set()方法内传递的索引处,否则会抛出异常.
Bur*_*ith 23
使用set()方法:参见doc
arraylist.set(index,newvalue);
public void setItem(List<Item> dataEntity, Item item) {
    int itemIndex = dataEntity.indexOf(item);
    if (itemIndex != -1) {
        dataEntity.set(itemIndex, item);
    }
}