DEV Community

Cover image for Char and Boolean in Kotlin
Jay Tillu
Jay Tillu

Posted on • Edited on

3

Char and Boolean in Kotlin

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 an error in kotlin.
Enter fullscreen mode Exit fullscreen mode
  • 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.

Follow me for more such content

Sentry mobile image

Tired of users complaining about slow app loading and janky UI?

Improve performance with key strategies like TTID/TTFD & app start analysis.

Read the blog post

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay