Operators in Scala
Here is a table listing some of the commonly used operators in Scala, categorized by type:
| Category | Operator | Description | Example |
|---|---|---|---|
| Arithmetic | + | Addition | 5 + 3 = 8 |
- | Subtraction | 5 - 3 = 2 | |
* | Multiplication | 5 * 3 = 15 | |
/ | Division | 6 / 2 = 3 | |
% | Modulus (Remainder) | 7 % 3 = 1 | |
| Relational | == | Equal to | 5 == 5 // true |
!= | Not equal to | 5 != 3 // true | |
> | Greater than | 5 > 3 // true | |
< | Less than | 3 < 5 // true | |
>= | Greater than or equal to | 5 >= 5 // true | |
<= | Less than or equal to | 3 <= 5 // true | |
| Logical | && | Logical AND | (true && false) // false |
| ` | ` | ||
! | Logical NOT | !true // false | |
| Bitwise | & | Bitwise AND | 5 & 3 = 1 |
| ` | ` | Bitwise OR | |
^ | Bitwise XOR | 5 ^ 3 = 6 | |
~ | Bitwise NOT | ~5 = -6 | |
<< | Left shift | 5 << 1 = 10 | |
>> | Right shift (signed) | 5 >> 1 = 2 | |
>>> | Right shift (unsigned) | 5 >>> 1 = 2 | |
| Assignment | = | Simple assignment | var x = 5 |
+= | Add and assign | x += 3 // x = x + 3 | |
-= | Subtract and assign | x -= 3 // x = x - 3 | |
*= | Multiply and assign | x *= 3 // x = x * 3 | |
/= | Divide and assign | x /= 3 // x = x / 3 | |
%= | Modulus and assign | x %= 3 // x = x % 3 | |
| Concatenation | + | String concatenation | "Hello" + " World" |
| Type | isInstanceOf | Check if an object is of a specific type | x.isInstanceOf[String] |
asInstanceOf | Cast an object to a specific type | x.asInstanceOf[String] | |
| Pattern Matching | match | Pattern matching (similar to switch-case in other languages) | x match { case 1 => ... } |
| Other | :: | Prepend element to list | 1 :: List(2, 3) // List(1, 2, 3) |
::: | Concatenate two lists | List(1, 2) ::: List(3, 4) | |
-> | Creates a tuple (key-value pair) | 1 -> "One" // (1, "One") | |
==> | Used in maps for key-value mapping | Map(1 ==> "One") | |
| Function Call | apply | Implicitly used to call an object like a function | list(0) == list.apply(0) |
Notes:
- Operators in Scala are just methods: In Scala, operators are methods. For example,
5 + 3is actually5.+(3). This allows for operator overloading and the creation of custom operators. - Precedence: Operator precedence in Scala is determined by the first character of the operator.

