scala char
Scala Char数据类型 (Scala Char Data Type)
Character (char) in Scala is a data type that is equivalent to 16-bit unsigned integer. The character data type stores a single character. It can be an alphabet, numbers, symbols, etc. The character takes 2 bytes while storing its literals.
Scala中的字符(char)是相当于16位无符号整数的数据类型。 字符数据类型存储单个字符。 它可以是字母,数字,符号等。该字符在存储其文字时占用2个字节。
When stored in memory, the character data type is stored as a Unicode number. This Unicode number is a unique unification number that is available for every character literal to be stored.
当存储在内存中时, 字符数据类型将存储为Unicode数字。 该Unicode编号是唯一的统一编号,可用于要存储的每个字符文字。
The use of char data type is not mandatory in scala. You can use var or val keyword in Scala to initialize them.
在scala中,不是必须使用char数据类型 。 您可以在Scala中使用var或val关键字进行初始化。
Syntax to define char variable in Scala:
在Scala中定义char变量的语法:
//With data type
var variable_name : Char = 'I';
//Without data type
val variable_name = 'i';
Example code to show Char data type in Scala
在Scala中显示Char数据类型的示例代码
object MyClass {
def main(args: Array[String]) {
var ch = 'I';
println("The value of character ch is "+ch);
ch = 'H';
println("The changed value of character ch is " + ch);
}
}
Output
输出量
The value of character ch is I
The changed value of character ch is H
Code logic:
代码逻辑:
The above code is used to show initialization and operation on Scala char data type. The code initializes the value 'I' to a variable ch and then prints "The value of character ch is I". After that, it changes the value if ch from 'I' to 'H' and then again prints the changed value.
上面的代码用于显示Scala char数据类型的初始化和操作。 该代码将值“ I”初始化为变量ch ,然后输出“字符ch的值为I” 。 之后,如果ch从“ I”更改为“ H” ,它将更改值,然后再次打印更改后的值。
翻译自: https://www.includehelp.com/scala/char-data-type-in-scala.aspx
scala char