I am new to scala programming language
In java if I have a data structure like HashMap<Integer,HashSet<LinkedList>>
If I don't initialize HashSet, I will get NullpointerException.
But in Scala, if I have HashMap<Int,HashSet<ListBuffer[Int]>>
How do I initialize nested HashSet?
When I use get() method.Should I use pattern match like
case Some =>
case None =>
Pattern matching as you describe is a good option.
An other one is to use getOrElse
:
map.getOrElse(10, Set.empty)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.