Scala Variables and Data Types
Variable is a name which is used to refer memory location. You can create mutable and immutable variable in scala. Let's see how to declare variable.
You can create mutable variable using var keyword. It allows you to change value after declaration of variable.
In the above code, var is a keyword and data is a variable name. It contains an integer value 100. Scala is a type infers language so you don?t need to specify data type explicitly. You can also mention data type of variable explicitly as we have used in below.
Another example of variable
The above code throws an error because we have changed content of immutable variable, which is not allowed. So if you want to change content then it is advisable to use var instead of val.
Data Types in Scala
Data types in scala are much similar to java in terms of their storage, length, except that in scala there is no concept of primitive data types every type is an object and starts with capital letter. A table of data types is given below. You will see their uses further.