由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - a newbie java question (转载)
相关主题
how to write a function take iterators as parameters?Java: use a HashSet to find the elements that are common in all lists
用那个design pattern好?Spark 和 Tensorflow 线性回归问题
再问两个C++问题一个C++的概念问题
这段code有啥问题?请教一个microarray问题
How many people use design patterns when coding?Interview question
如何取一个list的第i个elementintel icc hash_map 求救!
[请教]iterator and reference in C++ vectorSTL感觉实在太变态了
求推荐machine learning和data mining的书[菜鸟问题]类模板问题
相关话题的讨论汇总
话题: element话题: newbie话题: do话题: question话题: java
进入Programming版参与讨论
1 (共1页)
c******n
发帖数: 4965
1
【 以下文字转载自 SanFrancisco 讨论区 】
发信人: creation (努力自由泳50m/45sec !), 信区: SanFrancisco
标 题: a newbie java question
发信站: BBS 未名空间站 (Fri Jan 9 22:57:06 2009)
for a coding pattern like
for( Type element : myArrayList ) {
if ( checkSomeCondition(element) == true ) {
myArrayList.remove(element)
}
}
doesn't seem to work, because as the iterator goes on, the current link is
removed.
how do you normally do this simple coding pattern?
thanks
g*****g
发帖数: 34805
2
Instead of doing remove, do an add to a temporary collection,
then do a removeAll

【在 c******n 的大作中提到】
: 【 以下文字转载自 SanFrancisco 讨论区 】
: 发信人: creation (努力自由泳50m/45sec !), 信区: SanFrancisco
: 标 题: a newbie java question
: 发信站: BBS 未名空间站 (Fri Jan 9 22:57:06 2009)
: for a coding pattern like
: for( Type element : myArrayList ) {
: if ( checkSomeCondition(element) == true ) {
: myArrayList.remove(element)
: }
: }

c******n
发帖数: 4965
3
got answer in Sanfrancisco board
the method to use is
to use an explicit iterator,
and do iterator.remove() instead of list.remove(value)

【在 g*****g 的大作中提到】
: Instead of doing remove, do an add to a temporary collection,
: then do a removeAll

1 (共1页)
进入Programming版参与讨论
相关主题
[菜鸟问题]类模板问题How many people use design patterns when coding?
c++ iterator 弱问如何取一个list的第i个element
算法问题[请教]iterator and reference in C++ vector
c++ template question:求推荐machine learning和data mining的书
how to write a function take iterators as parameters?Java: use a HashSet to find the elements that are common in all lists
用那个design pattern好?Spark 和 Tensorflow 线性回归问题
再问两个C++问题一个C++的概念问题
这段code有啥问题?请教一个microarray问题
相关话题的讨论汇总
话题: element话题: newbie话题: do话题: question话题: java