Among java data types and "==" means:
1. Basic data types (also known as primitive data types): byte, short, char, int, long, float, double, boolean. Comparison between them, the application of double equal sign (==), comparison of their value.
2. The reference data types: when they are compared with (==), comparison is that they address stored in memory (to be exact, is the heap memory address).
For reference types, unless it is with a new object, the result of their comparison is true, or else compare the result is false. Because every new time, will re-open heap memory space.
Summary: == role:
basic types: the comparison is the same whether the value of
a reference type: Comp is the address of the value is the same
effect equals: the
reference type: By default, the comparison is the address value.
Note: However, we can according to their own override this method. General rewrite are generated automatically, comparing the value of the object member variables are the same.
Interview questions: Please explain the string (reference data types) in comparison "==" and equals () of the difference?
-
==: Comparison of two numeric string memory address (heap memory) are equal, the comparison value belongs;
-
equals (): compares the contents of two strings, comparing the content belongs.
When the string is equal to the determined future use equals ().