官术网_书友最值得收藏!

String Interpolators

We've already used String Interpolators, it's hard to avoid using them when they are available to you. Remember when we used them? Yes! When we were learning to create operators on our own:

println(s"Total Amount for order:: ${amountAfterTax(new Amount(firstOrderAmount))}")

This little s here is a String interpolator. While using these, we precede our String with a character named s, and inside double quotes of the String, we can use any variable with a $ and it'll be replaced by its value:

scala> val myAge = s"I completed my $age."
myAge: String = I completed my 25.

This is an example of how we can use interpolators. The s is not the only interpolator existing in Scala. We have a couple more interpolators. We'll go through them one by one.

  • The s interpolator
  • The f interpolator
  • The raw interpolator
主站蜘蛛池模板: 左贡县| 剑河县| 北安市| 平泉县| 文昌市| 桃园市| 青浦区| 章丘市| 昌宁县| 兰西县| 沁阳市| 大埔县| 夹江县| 石屏县| 广汉市| 英山县| 巴林右旗| 哈尔滨市| 张掖市| 类乌齐县| 云安县| 亳州市| 双城市| 巍山| 中牟县| 张家口市| 精河县| 临沂市| 巴彦县| 天门市| 阿图什市| 巴东县| 齐河县| 武威市| 榆社县| 陈巴尔虎旗| 阿拉尔市| 淮安市| 抚州市| 九龙县| 循化|