Contents    Page-10    Prev    Next    Page+10    Index   

== vs. .equals()

For all reference types, including Integer etc., the meaning of == and != is equality of pointer values, i.e. same data address in memory.

Rule: To test equality of the contents or value of a reference type, always use .equals().

Rule: To compare against null, use == or != .

Rule: To make an Integer from an int, either use:

These can save storage: