ELEVATE YOUR BUSINESS WITH

Limitless customization options & Elementor compatibility let anyone create a beautiful website with Valiance.

Operators in Kotlin

SELECT * FROM `itio_tutorial_master` WHERE `tutorial_menu`='25' AND `tutorial_submenu`='74' AND `tutorial_status`=1 LIMIT 1

Operators in Kotlin

📌 Operators in Kotlin

Operators in Kotlin are special symbols or keywords used to perform operations on variables and values. Kotlin provides a variety of operators for mathematical calculations, logical comparisons, and more.


✅ 1. Types of Operators in Kotlin

Kotlin supports the following categories of operators:

  1. Arithmetic Operators

  2. Assignment Operators

  3. Comparison Operators

  4. Logical Operators

  5. Bitwise Operators

  6. Unary Operators

  7. Increment and Decrement Operators

  8. Type Check and Type Cast Operators

  9. Range Operators


✅ 2. Arithmetic Operators

Used for mathematical operations like addition, subtraction, multiplication, etc.

OperatorDescriptionExampleOutput
+Addition5 + 38
-Subtraction7 - 43
*Multiplication6 * 318
/Division10 / 25
%Modulus (Remainder)10 % 31

📌 Example:

kotlin

fun() { val a = 10val b = 4 println("Addition: ${a + b}") println(") println("Multiplication: ${a * b}") println(") println("Modulus: ${a % b}")}


✅ 3. Assignment Operators

Used to assign values to variables.

OperatorExampleEquivalent To
=a = 10a = 10
+=a += 5a = a + 5
-=a -= 3a = a - 3
*=a *= 4a = a * 4
/=a /= 2a = a / 2
%=a %= 3a = a % 3


✅ 4. Comparison Operators

Used to compare two values. They return true or false.

OperatorDescriptionExampleOutput
==Equal to5 == 5true
!=Not equal to5 != 4true
<Less than3 < 5true
>Greater than7 > 2true
<=Less than or equal to5 <= 5true
>=Greater than or equal8 >= 6true


✅ 5. Logical Operators

Used to perform logical operations between Boolean values.

OperatorDescriptionExampleOutput
&&Logical AND (Both true)true && falsefalse
`
`Logical OR (At least one true)
!Logical NOT (Negation)!truefalse


✅ 6. Bitwise Operators

Bitwise operators are used to manipulate bits at a binary level.

OperatorDescriptionExampleOutput
andBitwise AND5 and 31
orBitwise OR5 or 37
xorBitwise XOR5 xor 36
invBitwise Inversion5.inv()-6
shlLeft Shift5 shl 110
shrRight Shift5 shr 12


✅ 7. Unary Operators

These operators act on a single operand.

OperatorDescriptionExampleOutput
+Unary plus+55
-Unary minus-5-5
++Increment Operatora++a+1
--Decrement Operatora--a-1
!Logical NOT!truefalse


✅ 8. Type Check and Cast Operators

Used to check or cast object types.

OperatorDescriptionExampleOutput
isCheck if an object is of a certain typex is Stringtrue
!isCheck if an object is not of a certain typex !is Inttrue
asCast an object to a specific typex as String-


✅ 9. Range Operator

The .. operator is used to create a range of numbers.

📌 Example:

kotlin

for (i in1..5) { println(i)}

Output:

12345

  • 1..5 → Includes both 1 and 5.

  • until → Excludes the upper bound (1 until 5 → 1 to 4).


✅ Conclusion

  • Arithmetic Operators → Perform mathematical operations.

  • Assignment Operators → Assign values with operations.

  • Comparison Operators → Compare values and return Boolean results.

  • Logical Operators → Perform Boolean logic operations.

  • Bitwise Operators → Work with binary data.

  • Unary Operators → Act on a single operand.

  • Type Operators → Perform type checking and casting.

  • Range Operator → Create number ranges for loops.

Disclaimer for AI-Generated Content:
The content provided in these tutorials is generated using artificial intelligence and is intended for educational purposes only.
html
docker
php
kubernetes
golang
mysql
postgresql
mariaDB
sql