Is there any difference between using <> and != for checking if two native objects are not equal to each other in Apex? i.e. String, Date etc.
I have only ever used != which has never failed me before.
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.Sign up to join this community
There is no practical difference, just different symbols for the same operation.
Do note that
<> is not documented as an expression operator in Apex.
While you can use either, I'd prefer
!= as it's documented and follows the principle of least surprise. Whatever you end up using, just be sure to us it consistently (don't switch between the two).
<> is/was historically used in both Microsoft Excel formulas and various SQL languages. To offer developers and administrators alike a familiar experience, Apex, SOQL, SOSL, and formulas allowed the use of either
!=. While apparently (at least partially) undocumented now, the
<> operator has been supported since the very first version of their respective technologies (formulas, SOQL/API, and Apex).
While you can use either, it is idiomatic to use
!= when writing new code, new formulas, and new API integrations. Having gone undocumented, it is likely that salesforce.com would like to eventually remove support for this operator in favor of the more standard