K
Kevin
Hi guys,
Just want to confirm:
for a ArrayList, in single thread mode (only one thread will access
this ArrayList), what is the best way to:
1) loop through all the element of this arraylist (for example, each
item of it is a String).
2) do some check on each item (for example, check if it equals to
"abc").
3) remove this item from the arraylist if the above check is true.
Is using iterator() and then use iterator.remove() the best way?
Like:
for (Iterator it = myarraylist.iterator(); it.hasNext(); )
{
String s = (String) it.next();
if (s.equals("abc"))
{
it.remove();
}
};
Thanks a log.
Just want to confirm:
for a ArrayList, in single thread mode (only one thread will access
this ArrayList), what is the best way to:
1) loop through all the element of this arraylist (for example, each
item of it is a String).
2) do some check on each item (for example, check if it equals to
"abc").
3) remove this item from the arraylist if the above check is true.
Is using iterator() and then use iterator.remove() the best way?
Like:
for (Iterator it = myarraylist.iterator(); it.hasNext(); )
{
String s = (String) it.next();
if (s.equals("abc"))
{
it.remove();
}
};
Thanks a log.