Scala equivalent for java.String.format

A nice, clean substitute for String.format is string interpolation (which will call toString on your values)

An example is shown here:

val t = Calendar.getInstance.getTime
var num = 7
val dec = 3.14
var text = "hello word"

s"""Test 1: $t"""
s"""Test 2: $num $dec $text"""

Which returns:

res21: String = Test 1: Thu Sep 17 21:57:02 EDT 2015
res22: String = Test 2: 7 3.14 hello world

Leave a Reply

Your email address will not be published. Required fields are marked *