Type conversion

Conversion between numeric types There are three most common numeric types: Int, Long, and Double. Sometimes, you may need to assign a value of one numeric type to a variable of another numeric type. In this case, you need to carry out type conversion by invoking a special function, for example, toInt(), toLong(), toDouble(), and so on.

The classification of basic types

In this topic, we will learn about the classification and properties of basic types in Kotlin. You may know some of them. Basic types can be separated into several groups according to their meaning. The types from the same group operate similarly, but they have different sizes and, as a consequence, represent different ranges of values.

Data types

What is a data type? All of us know that a number and a piece of text are pretty different. How do we know this? Well, you can perform arithmetic operations (such as multiplication) on numbers but not on texts. Kotlin also knows it. That’s why every variable has a type that determines what possible operations you can perform on this variable and which values you can…

Equality

You already know that objects are really complex structures and variables only point to objects. This time, you will learn about equality and how to understand that variables point to the same object. In addition, you will finally fully understand the meaning of the val keyword and avoid one of the most common beginner mistakes: assuming that the val keyword guarantees immutability.

Objects

Everything is an object In our life, we are always surrounded by objects: you drive a car, watch TV, read books, pay for bananas with your smartphone. In Kotlin, every time when you work with variables, you work with objects. For example, an integer 5 and a string “love” are objects. It is convenient because programmers are people, and people are used to dealing with objects.…

Val variables

Sometimes, you need to use a variable that should not be modified during the program execution. Such variables are known as constants, or val variables in Kotlin, where they are declared with the val keyword. The difference between a var variable and a val variable is that we cannot modify the value of a val variable once assigned.

String formatting

Kotlin String templates are a powerful tool for formatting strings. However, they have limitations, especially when one wants to print numerical values. Here, the String format() member function comes into play, which provides much more flexibility.