val
and var
both are used to declare a variable.
var is like general variable and its known as a mutable variable in kotlin and can be assigned multiple times.
val is like constant variable and its known as immutable in kotlin and can be initialized only single time.
val
is same as the final
modifier in Java. As you should probably know that we can not assign to a final
variable again but can change its properties.