Гость
Целевая тема:
Создать новую тему:
Автор:
Форумы / Java [игнор отключен] [закрыт для гостей] / Iterator / 7 сообщений из 7, страница 1 из 1
11.04.2005, 14:38
    #33008401
Urt
Urt
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Iterator
Что-то я запутался с итераторами: в книге пишут, что когда итерируешь,
то нельзя удалять элементы из списка. А если нужно что-то удалять?
Например, надо удалить все эл-ты, удовл. критерию каому-нибудь.
Неужели нельзя пробежать по списку, и, если надо - то удаляем?
...
Рейтинг: 0 / 0
11.04.2005, 14:43
    #33008420
Зашедший
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Iterator
В таком случае надо использовать стандартный метод итератора remove(). В таком случае он корректно обработает удаление.
...
Рейтинг: 0 / 0
11.04.2005, 14:48
    #33008439
wessen
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Iterator
Некоторые итераторы могут удалять. Это зависит от колекции лежащий в основе.

JavaDoc
public void remove()

Removes from the underlying collection the last element returned by the iterator (optional operation). This method can be called only once per call to next. The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method.

Throws:
UnsupportedOperationException - if the remove operation is not supported by this Iterator.
IllegalStateException - if the next method has not yet been called, or the remove method has already been called after the last call to the next method.
...
Рейтинг: 0 / 0
11.04.2005, 17:59
    #33009101
Urt
Urt
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Iterator
wessenНекоторые итераторы могут удалять. Это зависит от колекции лежащий в основе.

JavaDoc
public void remove()

Removes from the underlying collection the last element returned by the iterator (optional operation). This method can be called only once per call to next. The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method.

Throws:
UnsupportedOperationException - if the remove operation is not supported by this Iterator.
IllegalStateException - if the next method has not yet been called, or the remove method has already been called after the last call to the next method.


А если я просто итерирую List?
...
Рейтинг: 0 / 0
11.04.2005, 18:02
    #33009108
wessen
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Iterator
Urt wessenНекоторые итераторы могут удалять. Это зависит от колекции лежащий в основе.

JavaDoc
public void remove()

Removes from the underlying collection the last element returned by the iterator (optional operation). This method can be called only once per call to next. The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method.

Throws:
UnsupportedOperationException - if the remove operation is not supported by this Iterator.
IllegalStateException - if the next method has not yet been called, or the remove method has already been called after the last call to the next method.


А если я просто итерирую List?
Итерируй, кто тебе мешает то?
...
Рейтинг: 0 / 0
11.04.2005, 18:09
    #33009130
Urt
Urt
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Iterator
wessen Urt wessenНекоторые итераторы могут удалять. Это зависит от колекции лежащий в основе.

JavaDoc
public void remove()

Removes from the underlying collection the last element returned by the iterator (optional operation). This method can be called only once per call to next. The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method.

Throws:
UnsupportedOperationException - if the remove operation is not supported by this Iterator.
IllegalStateException - if the next method has not yet been called, or the remove method has already been called after the last call to the next method.


А если я просто итерирую List?
Итерируй, кто тебе мешает то?

И хочу удалить эл-т? Вдруг будет Exception?
...
Рейтинг: 0 / 0
11.04.2005, 18:12
    #33009141
wessen
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Iterator
Urt wessen Urt wessenНекоторые итераторы могут удалять. Это зависит от колекции лежащий в основе.

JavaDoc
public void remove()

Removes from the underlying collection the last element returned by the iterator (optional operation). This method can be called only once per call to next. The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method.

Throws:
UnsupportedOperationException - if the remove operation is not supported by this Iterator.
IllegalStateException - if the next method has not yet been called, or the remove method has already been called after the last call to the next method.


А если я просто итерирую List?
Итерируй, кто тебе мешает то?

И хочу удалить эл-т? Вдруг будет Exception?

Конкретно у List не будет.
...
Рейтинг: 0 / 0
Форумы / Java [игнор отключен] [закрыт для гостей] / Iterator / 7 сообщений из 7, страница 1 из 1
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]