constructor
This page contains a large collection of examples of how to use the Scala ArrayBuffer class.
Use the ArrayBuffer
class when you want to use a general-purpose, mutable indexed sequence in your Scala applications:
Kotlin secondary (auxiliary) class constructors (syntax, examples)
This page is a work in progress, but if you need to create a secondary class constructor in Kotlin, I hope it’s helpful.
This page contains a large collection of examples of how to use the methods on the Scala List class.
The Scala List class as an immutable, linear, linked-list class. It’s very efficient when it makes sense for your algorithms to (a) prepend all new elements, (b) work with it in terms of its head and tail elements, and (c) use functional methods that traverse the list from beginning to end, such as filter
, map
, foldLeft
, reduceLeft
.
- Read more about Scala Seq class: methods, examples, and syntax
- Log in to post comments
This page contains a large collection of examples of how to use the methods on the Scala Seq class.
Important note about Seq, IndexedSeq, and LinearSeq
As an important note, I use Seq
in the following examples to keep things simple, but in your code you should be more precise and use IndexedSeq
or LinearSeq
where appropriate. As the Seq
class Scaladoc states:
- Read more about Scala Vector class: method examples and syntax
- Log in to post comments
Scala: How to create a case class with multiple alternate constructors
As a brief note today, if you want to see how to create a Scala case class that defines multiple alternate constructors, I hope this example is helpful:
How to create a Java or Scala date from a Long value
Scala FAQ: How do I created a Scala Date
from a Long
value? When I give the Java Date class constructor a Long
value it returns a date from 1970.
Solution: You need to multiply the Long
value by 1000, and also make sure you pass a Long
value into the Date
constructor. The Scala REPL shows how this works: