In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
What is the basic data type of Kotlin, many novices are not very clear about this. In order to help you solve this problem, the following editor will explain it in detail. People with this need can come and learn. I hope you can get something.
Fun main () {/ / Integer val a: Byte = 1 / / 8-bit val b: Short = 2 / / 16-bit val c: Int = 3 / / 32 val c2 = 3 / / default integer Int val d: Long = 4 / / 64 val D2 = 4L / / with suffix L identifies Long long integer / / floating point val e: Float = 3.14f val e2 = 3.14f val f: Double Kotlin Boolean fun main () {val state: Boolean = trueval state2 = false} 3. Kotlin character type fun main () {/ / directly specify a single character as the character value val aChar: Char ='a' / / use the escaped character as the character value val covChar: Char ='\ r' / / use the Unicode code value to specify the character value val ch: Char = '\ u5475' println (ch) / / Oh} 4. Kotlin string fun main () {val str1: String = "str1" val str2 = "str2" / / string template val str3 = "$str1 length: ${str1.length}" println (str3) / / str1 length: 4 / / preserves indentation in the string Commonly used for typesetting printing val str4 = "" I am a programmer, 175cm "" .trimMargin () println (str4) / / original string, "|" as a boundary character, "|" before indentation will remove val str5 = "" | I am a programmer, | 175cm "" .trimMargin () println (str5) / / custom "&" as a boundary character Indentation before "&" removes val str6 = "" & I am a programmer & 175cm "" .trimMargin ("&") println (str6) / / the result is the same as "|" as the boundary character} 5. Kotlin nullable type fun main () {var aa: Byte? = null aa = 1 var bb: Short? = null bb = 2 var cc: Int? = null cc = 3 var dd: Long? = null dd = 4 var ee: Float? = null ee = 5f var ff: Double? = null ff = 6.0var gg: Boolean? = null gg = false} 6. Kotlin type conversion fun main () {var aa: Byte? = null aa.toInt () aa.toShort () aa.toLong () aa.toFloat () aa.toDouble () / / Security call Use?. Cc = null cc?.toLong () cc?.toString ()} 7. Kotlin binary, hexadecimal fun main () {/ / binary val bval1 = 0b101010 val bval2 = 0B1010110 var x =-0b11111111 println (x) / hexadecimal val tenVal1 = 0x132 val tenVal2 = 0X1d} is it helpful for you to read the above? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.