Java->Scala Remove Iterator<T>-Element from a JavaConversions-wrapped Iterable
Posted
by ifischer
on Stack Overflow
See other posts from Stack Overflow
or by ifischer
Published on 2010-06-05T17:51:00Z
Indexed on
2010/06/05
17:52 UTC
Read the original article
Hit count: 349
scala
I have to translate the following code from Java to Scala:
for (Iterator<ExceptionQueuedEvent> i = getUnhandledExceptionQueuedEvents().iterator(); i.hasNext();)
{
ExceptionQueuedEvent event = i.next();
try {
//do something
} finally {
i.remove();
}
}
I'm using the JavaConversions library to wrap the Iterable. But as i'm not using the original Iterator, i don't know how to remove the current element correctly from the collection the same way as i did in Java:
import scala.collection.JavaConversions._
(...)
for (val event <- events) {
try {
//do something
} finally {
//how can i remove the current event from events?
}
}
Can someone help me? I guess it's easy, but i'm still kinda new to Scala and don't understand what's going on when Scala wraps something of Java.
© Stack Overflow or respective owner