String Comparison in Apex
In Apex, to check if two variables have the same value, you can use string comparison. Apex provides built-in methods for this, and the comparison can be case-sensitive or case-insensitive.
Here is an example of comparing two strings to check if they have the exact same value in apex:
Loading...
In the above example:
- The keyword
String
is used to declare two string variables, string1 and string2, with the value ‘Hello’. - The
equals
method checks if two variables have exactly the same values, including case sensitivity. - The string values can also be compared using the
==
operator but it is case insensitive.
Note
To compare string in apex without considering the case sensitivity, you can use the equalsIgnoreCase() string method.
Try It Yourself
Loading...