Member-only story

String in Kotlin

billydharmawan
The Startup
Published in
4 min readMay 7, 2020
Photo by Jason Leung on Unsplash

Overview

String is one of the basic type in any programming languages, including Kotlin. I have never seen any application or program that does not deal with String. Have you ever? 🤔

That’s why I thought we should spend some time looking at the fundamentals of String. In this tutorial, we will learn the basics of String in the Kotlin programming language.

Initialise a String Object

Let’s start by learning how to initialise a String object. To initialise a String object, simply wraps your expression with double quotes ".

val myString = "This is my first String object"
myString::class
println(myString)// val myString: String
// class kotlin.String
// This is my first String object

Note that the expression myString::class gives us the instance type of an object.

Unlike in some other languages like Python, we cannot create a String object with single quotes '. If we try to do so, we will get a compilation error.

val myStringWithSingleQuotes = 'This is my first String object'// Too many characters in a character literal ''This is my first String object''

--

--

The Startup
The Startup

Published in The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +772K followers.

billydharmawan
billydharmawan

Written by billydharmawan

An ordinary man trying to leave a good legacy on earth

Responses (1)