This course is currently a work in progress. Please join the waitlist to receive regular updates.
How to compare integers in apex
In Apex, comparison is a common operation that lets developers run different paths of code during execution. Apex provides comparison operators to handle various comparison scenarios. The following are the common operators used for comparison:
Operator | Description | Example |
---|---|---|
== | Equal to | x == y |
!= | Not equal to | x != y |
> | Greater than | x > y |
< | Less than | x < y |
>= | Greater than or equal to | x >= y |
<= | Less than or equal to | x <= y |
The following code snippet shows how to compare two numbers in apex using various operators:
Loading...
In the above example:
- The variables numb1, numb2 are
Integer
variables. - The
==
operator checks if the two numbers numb1 and numb2, have the same value. - The
>
operator checks if numb1 is greater than numb2. - The
!
operator checks if numb1 is not equal to numb2. - The
&&
operator is used to join two comparison statements, and all of them must be true for the overall expression to evaluate as true. - The
||
operator is used to combine two comparison statements, and at least one of them must be true for the overall expression to evaluate as true.
Try It Yourself
Loading...