Collections - Concrete Mutable Collection Classes. You’ve now seen the most commonly used immutable collection classes that Scala provides in its standard library.
Take a look now at the mutable collection classes. Array Buffers An ArrayBuffer buffer holds an array and a size. Most operations on an array buffer have the same speed as for an array, because the operations simply access and modify the underlying array. Additionally, array buffers can have data efficiently added to the end. Scala> val buf = scala.collection.mutable.ArrayBuffer.empty[Int]buf: scala.collection.mutable.ArrayBuffer[Int] = ArrayBuffer()scala> buf += 1res32: buf.type = ArrayBuffer(1)scala> buf += 10res33: buf.type = ArrayBuffer(1, 10)scala> buf.toArrayres34: Array[Int] = Array(1, 10) List Buffers A ListBuffer is like an array buffer except that it uses a linked list internally instead of an array.
StringBuilders Just like an array buffer is useful for building arrays, and a list buffer is useful for building lists, a StringBuilder is useful for building strings. Everything You Ever Wanted to Know About Sealed Traits in Scala - Underscore. Sealed traits are essential for idiomatic Scala code, but many developers are hazy on the details of their working.
In this post we describe why you want to use them, and how to use them correctly to increase the quality of your code. We can explain sealed in terms of its low-level semantics, but I find it much more useful to start with the big picture. The most important use of sealed is in defining algebraic data types. Despite their fancy name, algebraic data types are just a way of modelling data in terms of two patterns: logical ors, such as List, which is a :: or Nil; and logical ands, such as ::, which has a head and a tail. In functional programming lingo we call the logical or a sum type and the logical and a product type.
Algebraic data types are really really important. Using some simple patterns we can mechanically translate the description of an algebraic data type into code. Notice the use of sealed (and final). Nscala-time/nscala-time. Time - Java date and time API - Home. Release 2.7 is the current latest release.
This release is considered stable and worthy of the 2.x tag. See the upgrade notes for full details. Joda-Time requires Java SE 5 or later and has no dependencies. There is a compile-time dependency on Joda-Convert, but this is not required at runtime thanks to the magic of annotations. Available in Maven Central. <dependency><groupId>joda-time</groupId><artifactId>joda-time</artifactId><version>2.7</version></dependency> Java Date and Calendar examples. This tutorial shows you how to work with java.util.Date and java.util.Calendar. 1.
Java Date Examples Few examples to work with Date APIs. Example 1.1 – Convert Date to String. SimpleDateFormat sdf = new SimpleDateFormat("dd/M/yyyy"); String date = sdf.format(new Date()); System.out.println(date); Java.util.Calendar Class. Scala School. Other Languages: About Scala school started as a series of lectures at Twitter to prepare experienced engineers to be productive Scala programmers.
Scala is a relatively new language, but draws on many familiar concepts. Thus, these lectures assumed the audience knew the concepts and showed how to use them in Scala. We found this an effective way of getting new engineers up to speed quickly. Approach We think it makes the most sense to approach teaching Scala not as if it were an improved Java but instead as a new language. Most of the lessons require no software other than a Scala REPL. Also You can learn more elsewhere: Getting Started with sbt — Running.
This page describes how to use sbt once you have set up your project.
It assumes you’ve installed sbt and created a Hello, World or other project. Interactive mode Run sbt in your project directory with no arguments: $ sbt Running sbt with no command line arguments starts it in interactive mode. Scala Function with Variable Arguments. Scala Standard Library 2.11.4 - root - Scala Standard Library 2.11.4 - _root_ Langref.org - scala and groovy - Strings.