Карта сайта Интеллектуальная поисковая системаДобавить свою ссылку по ключевому запросуПоисковая система v3.kz поможет ускорить индексацию вашего сайта выводит в Топ |
|
In this specific case, you should remove the elements in descending order. First index 5, then 3, then 1. This will remove the elements from the list without undesirable side effects. For (int j = i.length-1; j >= 0; j--) { list.remove(i[j]); }. It should be: ClientThread hey = clients.get(clients.size() - 1); clients.remove(hey); Or you can do. Clients.remove(clients.size() - 1); The minus ones are because size() returns the number of elements, but the ArrayLists first elements index is 0 and not 1. And, when you are using an iterator you should check if any item is avaitable using hasNext method of the iterator. There are anyway other methods like remove anyway! Your code will be something like: Public void removeItem(String description) {. Just as we add items to an ArrayList, we can remove items from an ArrayList. We use the Remove, RemoveAt and RemoveRange methods to remove items from an ArrayList. To remove an item from an arrayList I have used Object remove (int index) method. This method returns a reference to the item that was removed. The java.util.ArrayList.remove(Object) method removes the first occurrence of the specified element from this list, if it is present.If the list does not contain the element, it is unchanged. List list = Collections.synchronizedList(new ArrayList(...)); The iterators returned by this classs iterator and listIterator methods are fail-fast: if the list is structurally modified at any time after the iterator is created, in any way except through the iterators own remove or add methods... Removing Items From Arrays. There’s no doubt that arrays are incredibly useful when writing system administration scripts. Знакомство с ArrayList Методы ensureCapacity() и trimToSize() Метод indexOf() Просмотр всех элементов через цикл Метод contains() Метод remove() - удаление элемента Метод set() - замена элемента However, I am having trouble allowing users to remove items from their carts. What I have is a link next to the item to be deleted which is sent to a controlling JSP page which handles deleting the selected item from the arraylist. Информация взята v3.kz |
загрузка...
|