Char and Boolean in Kotlin

Jay Tillu
Blogs by Jay Tillu
Published in
2 min readDec 4, 2018

Char type

  • Characters are represented by the Char keyword.
  • They cannot be treated directly as numbers but you can perform explicit conversion functions according to your needs. Let’s understand this by example.
char a = 65  // Compile time error.
This code works fine in Java but will throw error in kotlin.
  • Character literals go in single quotes like ‘V’, ‘J’ etc.
  • In kotlin, strings are represented by the String class. String literals go inside the double quotes like “Viveki”, “Jay” etc.
  • Special characters can be escaped using a backslash.

The following escape sequences are supported:

  • \t — To print tab
  • \b — To use a backslash
  • \n — newline character
  • \r — carriage return
  • \’ — To print single quote
  • \” — To print a double quote
  • \\ — To print a backslash
  • \$ — To print the dollar sign
  • To encode any other character like hexadecimal or binary use Unicode escape sequence syntax: ‘\uFF004’.

Boolean Type

  • Boolean values are represented by Boolean keyword.
  • Boolean has two values either true or false. Both must be in lower case and cannot represent as 0 and 1.

So, guys, that’s it for char and boolean in kotlin. Feel free to let me know if I missed something.

Till then Keep Coding, Keep Loving. Catch you up in another article.

Jai Hind, Vande Mataram 🇮🇳

Wanna get in touch with me? Here are links. I’ll love to become your friend. 😊

My Site

My Blogs

LinkedIn

Github

Twitter

Facebook

Instagram

or just mail me at jd.tillu@gmail.com

--

--

Jay Tillu
Blogs by Jay Tillu

I am Frontend Web Developer and Hobbyist Blogger. As a Web Developer, I hold expertise in HTML, CSS, JavaScript, and React.