## What are Kotlin Operators?

Kotlin Operators are special symbols or characters that carry out operations on operands (variables and values). For example, + is an operator that performs addition. Kotlin has a set of operators to perform arithmetic, assignment, comparison operators and more. You will learn Kotlin operators in this article.

#### List Of Kotlin Operators

- Arithmetic Operations
- Assignments Operations
- Comparison operators
- Increments and decrements

#### 1. Kotlin Arithmetic Operations

arithmetic Operators Supports arithmetic operations and its comes under the Kotlin Operators

arithmetic Operations like summation, subtraction etc.

below table show some Operations.

Operator Symbol | Operator Usage |
---|---|

+ | Addition Operator String Concatination |

- | Substraction Operator |

* | Multiplication Operator |

/ | Division Operator |

% | Modulus Operator |

Example Of arithmetic Kotlin Operator

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
/** * Created by Androidteacher on 09/05/2017. * */ class KotlionOperator { fun aithmeticOperation() { val number1 = 9.5 val number2 = 3.5 var result: Double result = number1 + number2 println("number1 + number2 = $result") result = number1 - number2 println("number1 - number2 = $result") result = number1 * number2 println("number1 * number2 = $result") result = number1 / number2 println("number1 / number2 = $result") result = number1 % number2 println("number1 % number2 = $result") } } |

1 2 3 4 5 |
number1 + number2 = 13.0 number1 - number2 = 6.0 number1 * number2 = 33.25 number1 / number2 = 2.7142857142857144 number1 % number2 = 2.5 |

**+** is also used for connate or merge two string consider below example

1 2 3 4 5 6 7 8 9 10 |
fun stringPlusOperation(){ var one : String? one = "First" var two = "Second" var three : String = "Third" var result = one + " "+two+ " "+three println("First way Result is "+result) println("Second way Result is $result") } |

*output will be like*

1 2 |
First way Result is First Second Third Second way Result is First Second Third |

#### 2.Assignments Operations

Assignments Kotlin Operators are used to assign some values to variable. **= **

Expression | Meaning |
---|---|

a = 5 ,a = b | assign values right to left variable a has values 5 and variable a is equals to variable b |

a += b | a = a+b |

a -= b | a = a-b |

a *= b | a = a * b |

a /= b | a = a / b |

a %= b | a %= b |

#### 3.Comparison operators

Comparison operators are always returnĀ boolean values whether it is true or false

chart is given below

Operator | Meaning | Expression | Meaning |
---|---|---|---|

> | greater than | a > b | a is greater then b then true |

< | less than | a < b | a is less then b then true |

>= | greater than or equals to | a >= b | a is greater or equal to b then true |

<= | less than or equals to | a < = b | a is less or equal to b then true |

== | is equal to | a == b | a is equals to b then true |

!= | not equal to | a != b | a does not equal then true |

#### 4.Increments and decrements

Increments and decrement will help you to increase and decrese value of variable by 1

after variable ++ will increase value by 1

same way — will decrese value by 1

Expression | Meaning |
---|---|

a++ | a = a+1 |

a-- | a = a-1 |