You can define a string using ‘String’ type.
Syntax
var variable_name : String = "message"
Example
var msg : String = "Hello, how are you
scala> var msg : String = "Hello, how are you"
var msg: String = Hello, how are you
scala> print(msg)
Hello, how are you
Since Scala infers type, you can omit String type while defining the variable.
scala> var name = "Krishna"
var name: String = Krishna
As you see, I defined the variable ‘name’ but not specified type. Scala infers the type automatically depends on the value it holds.
No comments:
Post a Comment