Comparisons between arrays in Java

Source: Internet
Author: User
Tags array arrays
Comparison | The array//null element is equal.
boolean[] bArr1 = null;
boolean[] bArr2 = null;
Boolean B = Arrays.equals (BARR1, BARR2); True

Compares a two Boolean array.
BARR1 = new boolean[]{true, false};
BARR2 = new boolean[]{true, false};
b = arrays.equals (BARR1, NULL); False
b = Arrays.equals (BARR1, BARR2); True

For primitive types of arrays, you can use Equals ().
b = arrays.equals (New byte[]{0}, New byte[]{0}); True
b = arrays.equals (new char[]{' A '}, new char[]{' a '}); True
b = arrays.equals (New short[]{0}, New short[]{0}); True
b = arrays.equals (New int[]{0}, New int[]{0}); True
b = arrays.equals (New long[]{0l}, New long[]{0l}); True
b = arrays.equals (New float[]{0f}, New float[]{0f}); True
b = arrays.equals (New double[]{0d}, New double[]{0d}); True

If you compare an array of type object, the null element is equal.
If the element is not NULL, the Java virtual Opportunity automatically invokes Object.Equals ().
b = arrays.equals (new string[]{"A"}, new string[]{"a"}); True
b = arrays.equals (New String[]{null}, New String[]{null}); True
b = arrays.equals (new string[]{"A"}, new String[]{null}); False


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.