|
|
|
Iterator
|
|||
|---|---|---|---|
|
#18+
Что-то я запутался с итераторами: в книге пишут, что когда итерируешь, то нельзя удалять элементы из списка. А если нужно что-то удалять? Например, надо удалить все эл-ты, удовл. критерию каому-нибудь. Неужели нельзя пробежать по списку, и, если надо - то удаляем? ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 11.04.2005, 14:38 |
|
||
|
Iterator
|
|||
|---|---|---|---|
|
#18+
В таком случае надо использовать стандартный метод итератора remove(). В таком случае он корректно обработает удаление. ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 11.04.2005, 14:43 |
|
||
|
Iterator
|
|||
|---|---|---|---|
|
#18+
Некоторые итераторы могут удалять. Это зависит от колекции лежащий в основе. 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. ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 11.04.2005, 14:48 |
|
||
|
Iterator
|
|||
|---|---|---|---|
|
#18+
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? ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 11.04.2005, 17:59 |
|
||
|
Iterator
|
|||
|---|---|---|---|
|
#18+
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? Итерируй, кто тебе мешает то? ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 11.04.2005, 18:02 |
|
||
|
Iterator
|
|||
|---|---|---|---|
|
#18+
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? ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 11.04.2005, 18:09 |
|
||
|
Iterator
|
|||
|---|---|---|---|
|
#18+
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 не будет. ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 11.04.2005, 18:12 |
|
||
|
|

start [/forum/topic.php?fid=59&msg=33009141&tid=2152610]: |
0ms |
get settings: |
5ms |
get forum list: |
9ms |
check forum access: |
2ms |
check topic access: |
2ms |
track hit: |
43ms |
get topic data: |
6ms |
get forum data: |
1ms |
get page messages: |
26ms |
get tp. blocked users: |
1ms |
| others: | 186ms |
| total: | 281ms |

| 0 / 0 |
