equals比内容,==比引用,数组的equals()如何实现

解决方案 »

  1.   

    equals
    public static boolean equals(int[] a,int[] a2)
    Returns true if the two specified arrays of ints are equal to one another. Two arrays are considered equal if both arrays contain the same number of elements, and all corresponding pairs of elements in the two arrays are equal. In other words, two arrays are equal if they contain the same elements in the same order. Also, two array references are considered equal if both are null.
    Parameters:
    a - one array to be tested for equality.
    a2 - the other array to be tested for equality. 
    Returns:
    true if the two arrays are equal
      

  2.   

    equals(object[] a1,object[] a2) 返回一个boolean
      

  3.   

    数组的equals就是Object的equals方法,也就是==
      

  4.   

    你想实现数组的equals方法,如果是指重载的话,是不可能的,
    因为你没法public class Object[] {  }要比较两个数组是否相同,可以使用java.util.Arrays中的equals方法