I need to write a code that compares performance of Java’s ArrayList with Scala’s List. I am having a hard time getting the Scala List working in my Java code. Can some one post a real simple “hello world” example of how to create a Scala List in java code (in a .java file) and add say 100 random numbers to it?
PS: I am quite good at Java but have never used Scala.
It’s easier to use Java collections in Scala than the other way around, but since you asked:
This compiles with javac with scala-library.jar in the classpath:
You can invoke from the Scala REPL:
To use a Java collection from Scala, you don’t have to do anything special: