// null 元素是相等的. Z(R28n\q
boolean[] bArr1 = null; a@ n eU~
boolean[] bArr2 = null; Rr!VD(V
boolean b = Arrays.equals(bArr1, bArr2); // true oEmSZd)`LF
q% HXd/3
// 比较两个boolean数组. L+ ,
bArr1 = new boolean[]{true, false}; qi.=VM s
bArr2 = new boolean[]{true, false}; c>c,V?
b = Arrays.equals(bArr1, null); // false i#O.{q=x
b = Arrays.equals(bArr1, bArr2); // true ,k'nN^gmf
=G[1]&j|
// 对于原生类型的数组可以用equals(). qvE;N-3N
b = Arrays.equals(new byte[]{0}, new byte[]{0}); // true */^8WK%3d
b = Arrays.equals(new char[]{'a'}, new char[]{'a'}); // true <b>X;WI5hd
b = Arrays.equals(new short[]{0}, new short[]{0}); // true $.p ]U w
b = Arrays.equals(new int[]{0}, new int[]{0}); // true A\[De9*
b = Arrays.equals(new long[]{0L}, new long[]{0L}); // true 0~CK^_.&!|
b = Arrays.equals(new float[]{0F}, new float[]{0F}); // true mR2N:Nx 9
b = Arrays.equals(new double[]{0D}, new double[]{0D}); // true D]%2XMb
jdV6dKE
// 如果比较的是Object型的数组,null元素是相等的. rOZ }X5
// 如果于元素不是null, Java虚拟机会自动调用Object.equals(). ]{oOHj
b = Arrays.equals(new String[]{"a"}, new String[]{"a"}); // true ~UK&}%jQ
b = Arrays.equals(new String[]{null}, new String[]{null}); // true n?um9QP
b = Arrays.equals(new String[]{"a"}, new String[]{null}); // false
查看本文来源