查看scala變量數據類型
1)Scala數據類型 (1) Scala Data Types)
Scala has the same set of data types as in Java. The traditional 14 data types are inherited as it is in Scala.
Scala具有與Java中相同的數據類型集。 傳統的14種數據類型在Scala中被繼承。
The Following are Valid Data Types in Scala.
以下是Scala中的有效數據類型。
S. No. | Data Type | Bit Size | Range |
---|---|---|---|
1 | Byte | 8 | -128 to 127 |
2 | Short | 16 | -32768 to 32767 |
3 | Int | 32 | -2147483648 to 2147483647 |
4 | Long | 64 | -9223372036854775808 to 9223372036854775807 |
5 | Float | 32 | IEEE 754 single-precision |
6 | Double | 64 | IEEE 754 double-precision |
7 | Char | 16 | Unicode : U+0000 to U+FFFF |
8 | String | *Char Sequence | |
9 | Boolean | 1 | true/ false |
10 | Unit | *No Value | |
11 | Null | *Null / empty reference | |
12 | Nothing | *Subtype, includes no value | |
13 | Any | *any object | |
14 | AnyRef | *reference type |
序號 | 數據類型 | 位大小 | 范圍 |
---|---|---|---|
1個 | 字節 | 8 | -128至127 |
2 | 短 | 16 | -32768至32767 |
3 | 整數 | 32 | -2147483648至2147483647 |
4 | 長 | 64 | -9223372036854775808至9223372036854775807 |
5 | 浮動 | 32 | IEEE 754單精度 |
6 | 雙 | 64 | IEEE 754雙精度 |
7 | 燒焦 | 16 | Unicode:U + 0000至U + FFFF |
8 | 串 | *字符序列 | |
9 | 布爾型 | 1個 | 真假 |
10 | 單元 | *沒有價值 | |
11 | 空值 | *空/空參考 | |
12 | 沒有 | *子類型,不包含任何值 | |
13 | 任何 | *任何物體 | |
14 | 任何參考 | *參考類型 |
2)Scala中的文字 (2) Literals in Scala)
A literal is a value that can be assigned to a variable. Literals are basic constants that are assigned to the variable.
文字是可以分配給變量的值。 文字是分配給變量的基本常量。
Types of literals
文字類型
Integer Literals: Literals of type int or type Long. Integer literals can be declared using suffix L or I.
整數文字 :int類型或Long類型的文字。 整數文字可以使用后綴L或I聲明。
Example:
Decimal Literal : var i = 10L
Hexadecimal Literal : var I = 0xFFF
Float Literals: Literals of type float or type double. They use Suffix f/F for float and D/d for double.
Float字面量 :float或double類型的字面量。 他們將后綴f / F用于浮點,將D / d用于雙精度。
Example: Float Literal : var i = 12.35f Double Literal : var I = 123.5445d
Character Literals: Unicode characters like 'f'
字符字面量 :Unicode字符,例如“ f”
String Literal: Multiple character literal like 'Include'
字符串文字 :多字符文字,例如“包含”
Multi-Line Literal: Muti-line string Literal.
多行文字 :多行字符串Literal。
Example: "Include Help is of the best Programming tutor"
Boolean: A literal with any of two values, True/False.
布爾值 :具有兩個值True / False的文字。
3)Scala中的變量 (3) Variables in Scala)
A variable is some space in the memory that stores values. The memory space allocated to the variable is based on its data type.
變量是內存中存儲值的一些空間。 分配給變量的內存空間基于其數據類型。
Declaration of variables in Scala
在Scala中聲明變量
In Scala, there are two types of variables 1) mutable (just like normal variables whose values can be changed during program execution) and 2) immutable (just like a constant whose value cannot be changed during program execution).
在Scala中,有兩種類型的變量:1) 可變的 (就像在程序執行過程中可以更改其值的普通變量一樣)和2) 不可變的 (就像在程序執行過程中其值不能更改的常量一樣)。
Mutable variables are declared by using the "var" keyword, and immutable variables are declared by using the "val" keyword.
可變變量使用“ var”關鍵字聲明,不可變變量使用“ val”關鍵字聲明 。
Example:
例:
var I = 23 // this value can be changed val H = 12 //this value cannot be changed.
Although variable data type is detected by Scala but you can explicitly define it.
盡管Scala檢測到可變數據類型,但是您可以顯式定義它。
var I : string = "Include" val H : string = "Help"
翻譯自: https://www.includehelp.com/scala/literal-variables-and-data-type.aspx
查看scala變量數據類型