Home > Java > JavaBase > body text

The difference between java = and ==

王林
Release: 2019-11-09 16:25:30
Original
4520 people have browsed it

The difference between java = and ==

Difference:

In Java, = is an assignment operation, while == is used to determine whether the values ​​are equal.

Example:

a=b  //就是把b的值赋予给a;
a==b  //就是判断a等于b
Copy after login

Judgment condition for judging whether the two values ​​compared by the == operator are equal:

1 , if two values ​​have the same type, then test for equality; if the two values ​​are exactly the same, they are equal; if they are not exactly the same, then they are not equal.

2. If two values ​​are of different types, they may still be equal. Use the following rules and type conversions to check their equality:

If one value is null and the other value is undefined, they are equal;

If one value is a number, the other value Is a string, convert the string into a number, and then use the converted value for comparison;

If a value is true, convert it to 1, and then compare. If a value is false, convert it to 0, and then compare;

If one value is an object and the other value is a number or string, convert the object into a primitive type value, and then compare;

Other combinations are not equal.

Recommended tutorial: java tutorial

The above is the detailed content of The difference between java = and ==. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template