Learn Kotlin: Basic Operators

Some of the many basic operators in Kotlin

Mathematical operations like addition, substraction, multiplication, and division comes built-in with Kotlin.

However there are more available basic operators we can use to perform operations on variables and values. Learning these operators is important as you will do operations on variable and values a lot.

In the example below, we use the + operator to add together two values, a variable with a value, and a variable with another variable.

Addition operator example

We will learn four different categories of operators : arithmetic, assignment, comparison, and logical. You can use all four of them for operations of two values, a variable with a value, and a variable with another variable just like the addition operator example above.

1. Arithmetic operators

— are used to perform common mathematical operations.

Kotlin arithmetic operators
Arithmetic operators in action

2. Assignment operators

— are used to assign values to variables.

We use the assignment operator (=) to assign a value to a variable.

For example : val x = 10

We assign the value 10 to a variable named x.

Here is a list of all assignment operators:

Kotlin assignment operators list

3. Comparison operators

— are used to compare two values and will return boolean (true or false).

Kotlin comparison operators

4. Logical operators

— are used to determine the logic between variables or values and will return boolean (true or false).

Kotlin logical operators

That’s basically it. That’s all you need to know about Kotlin basic operators. You can save this article for your future reference. Thank you so much for reading. If you like these articles, let me know in the comment section below. You can also give suggestion, I’m open for any kind of feedback.

— Learn Kotlin Series —

  1. Learn Kotlin: Introduction
  2. Learn Kotlin: Hello World!
  3. Learn Kotlin: Variables
  4. Learn Kotlin: Data Types
  5. Learn Kotlin: Basic Operators (this article)
  6. Learn Kotlin: Functions

--

--

--

Android Developer. Currently residing in Jambi, Indonesia. https://romnan.my.id

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

EMPEX Speaker: Juan Soto

Mobile Test Strategy Tips using XP

Interrupts and Request Memoization

Among us game animation using Flutter

HTTP Server Configuration with SSL & Multi-Hosts using same IP

High Availability with AxonServer and Axon Framework

GitOps: Build infrastructure resilient applications

Getting Started with Neo4j and Gephi Tool

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Deddy Romnan Rumapea

Deddy Romnan Rumapea

Android Developer. Currently residing in Jambi, Indonesia. https://romnan.my.id

More from Medium

Learning Ktor — Quick and Dirty Scratch Notes

Programming code displayed on a screen.

Hackerrank: Day Of The Programmer

How do I convert 2018–04–10T04:00:00.000Z string to DateTime?

Let’s talk about head first Java