In earlier versions of Scala you can use List.make(100, 1), but that is now deprecated. What is the new proper way to do it?
This is the first method we use to append Scala List using the operator “:+”. The syntax we use in this method is; first to declare the list name and then use the ':+' method rather than the new element that will be appended in the list. The syntax looks like “List name:+ new elements”.
Show activity on this post. => is the "function arrow". It is used both in function type signatures as well as anonymous function terms. () => Unit is a shorthand for Function0[Unit] , which is the type of functions which take no arguments and return nothing useful (like void in other languages).
In order to concatenate two lists we need to utilize concat() method in Scala. In above syntax, l1 is list1 and l2 is list2.
In Java terms, Scala's Seq would be Java's List , and Scala's List would be Java's LinkedList . Note that Seq is a trait , which is equivalent to Java's interface , but with the equivalent of up-and-coming defender methods.
As described in the deprecated note:
@deprecated("use `fill' instead", "2.8.0")
try this:
List.fill(100)(1)
As the documentation says:
List.fill(100)(1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With