In Java, the == operator is used to compare objects for equality, it checks whether two objects refer to the same memory location: Value comparison: Basic types compare values. Reference comparison: Reference types compare memory addresses. Self-reference: Two references to the same object return true. Null values: Two null values return true, otherwise false.
Meaning of == in Java
In Java, the == operator is used to compare two Object equality. It checks whether the two operands point to the same memory location, i.e. whether they refer to the same object.
Detailed explanation:
Example:
<code class="java">int a = 5; int b = 5; System.out.println(a == b); // 输出 true:值相等 String name1 = "John"; String name2 = "John"; System.out.println(name1 == name2); // 输出 true:引用同一对象 String name3 = new String("John"); System.out.println(name1 == name3); // 输出 false:引用不同的对象 Object obj1 = null; Object obj2 = null; System.out.println(obj1 == obj2); // 输出 true:都是 null</code>
Note: The
The above is the detailed content of What does == mean in java. For more information, please follow other related articles on the PHP Chinese website!