I have some java code I am trying to convert to scala:
package hello;
class HelloWorldApp {
public static void main(String[] args) {
public SortedMap<Long, Long> toDates = new TreeMap<>();
Iterator<Long> iterLong = toDates.keySet().iterator();
while( iterLong.hasNext() )
{
System.out.println("TEST");
}
}
}
I used a converter to get this:
package hello
//remove if not needed
import scala.collection.JavaConversions._
object HelloWorldApp {
def main(args: Array[String]): Unit = {
val toDates: SortedMap[Long, Long] = new TreeMap[Long, Long]()
val iterLong: Iterator[Long] = toDates.keySet.iterator()
while (iterLong.hasNext) println("TEST")
}
}
The problem is the iterator() call really is not liked in scala (which I am executing through spark)
<console>:190: error: type mismatch;
found : java.util.Iterator[Long]
required: scala.collection.Iterator[Long]
val iterLong: Iterator[Long] = toDates.keySet.iterator()
I understand what he error is saying basically. Though, I am not sure how to force the type of scala.collection on the keySet.iterator() call.
I did do this:
val iterLong: scala.collection.Iterator[Long] = toDates.keySet.iterator()
To no avail What else can I add to have that iterator come back and work correclty in the loop?
toDates.keys.toIteratorJavaConverters._and call.asScalawhen needed. See here