Evaluate the null and null values in Java

Source: Internet
Author: User

In java, when determining whether a value values is null, most people use if (values. equals ("null"), this method cannot be used. Because the syntax is correct, no error is reported during program compilation, but a Bug occurs during runtime, the program is suspended. This is because values = "null" and values = null are not the same thing.

The correct use is if (values! = Null)

When determining whether it is null, the correct method is: if ((""). equals (values), Here special attention: Using if (values = "") This method is firmly opposed, because: this method is used to determine whether the "Address" and "" of values are the same, rather than to determine whether the two values are the same. We recommend that you set the constant to the front when determining whether the values are equal. This will prevent the assignment of values with less equal numbers.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.