官术网_书友最值得收藏!

Data types in Kotlin

The basic data types in Kotlin are numbers, characters, Boolean, arrays, and strings. These are described as follows:

  • Number: Kotlin provides the following built-in types that represent numbers, similar to Java:
Unlike in Java, c haracters are not nu mbers in Kotlin.
    • Byte: Byte is a one-byte or 8-bit type for which values range from -128 to 127
    • Short: Short is a two-byte or 16-bit type for which values range from -32768 to 32767
    • Int: Int is a four-byte or 32-bit type for which values range from -2^31 to 2^31-1
    • Long: Long is an eight-byte or 64-bit type that can have values from -2^63 to 2^63-1
    • Double: Double is a double-precision, 8-byte, or 64-bit floating point
    • Float: Float is a single-precision, 4-byte or 32-bit floating point
    • Char: Char is used to represent a character in Kotlin, two-byte or 16-bit long, and is used to represent unicode characters

Char is a type used to represent characters. This is represented as follows:

val ch = 'a'
  • Boolean: Kotlin has a Boolean type to represent Booleans. It takes either true or false:
val isValid = true
val flag = false
If you are using IntelliJ IDEA, you can place your cursor inside the variable and press Ctrl + Shift + P to see its type.
主站蜘蛛池模板: 宁津县| 武鸣县| 宁陕县| 梁平县| 新乐市| 天台县| 灯塔市| 凉山| 蓬安县| 佛坪县| 资阳市| 明光市| 九台市| 台中市| 台湾省| 天长市| 南郑县| 甘肃省| 滕州市| 龙门县| 新丰县| 沭阳县| 监利县| 芷江| 岳西县| 盖州市| 大田县| 新建县| 抚州市| 三江| 轮台县| 新巴尔虎右旗| 剑河县| 武汉市| 肇州县| 呼和浩特市| 江安县| 伊宁市| 和林格尔县| 达日县| 瓮安县|