3.10. Equality
Primitive Data Value Equality: ==, !=
Given that a and b represent operands of primitive data types, the primitive data value equality operators are defined as shown in Table 3.7.
a == b | a and b are equal? That is, have the same primitive value? (Equality) |
a != b | a and b are not equal? That is, do not have the same primitive value? (Inequality) |
The equality operator == and the inequality operator != can be used to compare primitive data values, including boolean values. Binary numeric promotion is applied to the nonboolean operands of these equality operators.
int year = 2002; boolean isEven = year % 2 == 0; // true. boolean compare = '1' == 1; // false. Binary numeric promotion applied. ...
Get Programmer's Guide to Java™ Certification, A: A Comprehensive Primer, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.