/**
n o w j a v a . c o m - 时 代 Java
**/
//package com.nowjava;
import java.lang.reflect.Array;
public class Main {
public static void main(String[] argv) throws Exception {
Object array1 = "nowjava.com";
Object array2 = "nowjava.com";
System.out.println(areArraysEqual(array1, array2));
}
/**
* Compares the two specified arrays. If both passed objects are
* <code>null</code>, <code>true</code> is returned. If both passed
* objects are not arrays, they are compared using <code>equals</code>.
* Otherwise all array elements are compared using <code>equals</code>.
* This method does not handle multidimensional arrays, i.e. if an
* array contains another array, comparison is based on identity.
* @param array1 the first array
* @param array2 the second array
* @return <code>true</code> if the arrays are equal, <code>false</code>
* otherwise
*/
public static boolean areArraysEqual(Object array1, Object array2) {
if (null == array1 && null == array2)
/*来自
n o w j a v a . c o m*/
return true;
if (null == array1 || null == array2)
return false;
if (!array1.getClass().isArray() && !array2.getClass().isArray())
return array1.equals(array2);
if (!array1.getClass().isArray() || !array2.getClass().isArray())
return false;
int length1 = Array.getLength(array1);
int length2 = Array.getLength(array2);
if (length1 != length2)
return false;
for (int ii = 0; ii < length1; ii++) {
/**代码未完, 请加载全部代码(NowJava.com).**/
本文系作者在时代Java发表,未经许可,不得转载。如有侵权,请联系nowjava@qq.com删除。