Import statements in Scala

One more baby step into Scala, in this second of a series of posts. Import statements.

Scala’s import statements are very similar to Java’s, but with some small differences that allow you to write more concise code. Take a look at the following examples:

1. _ instead of *


import java.util.*;


import scala.util._

2. Importing multiple classes from the same package


import java.util.Date;
import java.util.Collection;
import java.util.List;


import java.util.{Date, Collection, List}

3. Renaming


// can't be done


import java.util.{Collection => JavaCollection}

Although I used Java classes in almost all the examples above, you can of course use the same syntax for all the Scala classes as well.

That’s all for now! What do you want to read next about Scala? Leave a comment!

This entry was posted in java, scala and tagged , , , . Bookmark the permalink.

1 Response to Import statements in Scala

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s