Data Type | Description | Size (bits) | Range/Values | Example |
---|---|---|---|---|
Numeric | ||||
Byte | Signed integer | 8 | -128 to 127 | 10 , -5 |
Short | Signed integer | 16 | -32768 to 32767 | 10000 , -2000 |
Int | Signed integer | 32 | -2,147,483,648 to 2,147,483,647 | 123456789 , -1000000 |
Long | Signed integer | 64 | -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 | 1000000000000 , -5000000000 |
Float | Floating-point | 32 | ±1.40129846432481707e-45 to ±3.40282346638528860e+38 | 3.14f , -2.5f |
Double | Floating-point | 64 | ±4.94065645841246544e-324 to ±1.79769313486231570e+308 | 3.14159 , -2.71828 |
Text | ||||
Char | Single character | 16 | Any valid Unicode character | 'a' , '?' , '한' |
String | Sequence of characters | Variable | "Hello" , "Kotlin" | |
Boolean | ||||
Boolean | Boolean value | true , false | ||
Other | ||||
Array | Fixed-size collection of elements of the same type | Variable | arrayOf(1, 2, 3) , arrayOf("a", "b") |
- Size: The size of
String
andArray
types is dynamic and depends on the content. - Boolean size: The exact size of a
Boolean
isn't precisely defined in the language specification and can vary depending on the JVM implementation and platform. It's often optimized to be efficient. - Character size: Kotlin uses UTF-16 encoding for characters, so each
Char
takes 16 bits (2 bytes).
This table gives you a good overview of Kotlin's basic data types. Remember that efficient memory management is often handled by the Kotlin compiler and the JVM, so you usually don't need to worry about the exact size of these types in your everyday coding.
0 Comments
Post a Comment