- + : Addition Operator
- – : Subtraction Operator
- * : Multiplication Operator
- / : Division Operator
- % : Modulus Operator
Basic Assignment Operator
The assignment operator
= assigns a value to a variable.
Augmented Assignment Operators
This operators are also called compound assignment operators in other programming languages.
Above can be simplified as below
- a = a + b to a += b
- a = a – b to a -= b
- a = a * b to a *= b
- a = a / b to a /= b
- a = a % b to a %= b
- Unary Plus Operator + : It does not change sign of the value.
- Unary Minus Operator – : It changes sign of the value.
- Unary Inversion Operator ! : It inverts the value.
- Unary Increment Operator ++ : It can be pre-increment operator mentioned by ++a or post-increment operator mentioned by a++.
- Unary Decrement Operator — : It can be pre-decrement operator mentioned by –a or post-decrement operator mentioned by a–.
Comparison & Equality Operators
Boolean Logical Operators
- || : If any of all boolean expressions is true
- && : If all boolean expressions are true
- shl : Signed shift left (Equivalent of << operator)
- shr : Signed shift right (Equivalent of >> operator)
- ushr : Unsigned shift right (Equivalent of >>> operator)
- and : Bitwise and (Equivalent of & operator)
- or : Bitwise or (Equivalent of | operator)
- xor : Bitwise xor (Equivalent of ^ operator)
- inv : Bitwise inversion (Equivalent of ` operator)
String Concatenation Operator
For string concatenation, + operator is used.
$ operator is used for adding template expression inside a string.
Safe Call Operator
Safe call operator ?. is used to call the method only if object is not null.
Elvis operator ?: returns its first expression if it is not null, otherwise it returns the second expression.
Non Null Assertion Operator
This operator !! checks value null or not. If value is null then it throws KotlinNullPointerException.
is operator is used to check data type of variable at runtime. Its negated form is !is.
as operator is used for to convert one type of variable to another. It is called unsafe cast operator. !as is called safe cast operator.
in operator is used to check whether object belongs to collection. its negated form is !in.
Double Colon Operator
Double colon operator :: is used to create a class or a function reference.
This operator .. is used to create range of values.
Index Access Operator
This operator is used to get a obtain a value from an array.