== operator compares whether the values of two operands are equal. Basic data types compare values, and objects compare references. Non-basic types can override the equals() method or use == to compare references.
== Operator in Java
==== Operator
In Java, == is an equality operator that compares the values of two operands for equality.
Syntax
<code class="java">boolean == (value1, value2);</code>
Return result
If the values of value1 and value2 are equal, return true; otherwise, return false .
Usage scenarios
== operator is usually used to compare the value equality of basic data types (such as int, double, char). For objects, the == operator compares their references, not their values.
Non-basic types
For non-basic types (such as objects), you can compare their actual values using the following method:
Example
<code class="java">// 基本数据类型比较 int a = 5; int b = 5; System.out.println(a == b); // 输出:true // 对象引用比较 String str1 = new String("hello"); String str2 = new String("hello"); System.out.println(str1 == str2); // 输出:false</code>
The above is the detailed content of \nwhat does it mean in java. For more information, please follow other related articles on the PHP Chinese website!