class Person{
public static void main(Strng[] args){
Person p=new Person();
int[] i1={1,2,3,4};
int[] i2={1,2,3,4};
boolean b=p.equals(i1,i2);
if(b){
System.out.println("The same !");
}else{
System.out.println("They are different !");
}
}
“JDK API中提供了数组比较的方法是equals(int[] a,int[] a2);如果两个数组包含相同数量的元素,并且两个数组中的所有相应元素对都是相等的,则认为这两个数组是相等的。换句话说,如果两个数组以相同顺序包含相同的元素,则两个数组是相等的。此外,如果两个数组引用都为 null,则认为它们是相等的。”
那为什么运行都是false?
高手解释下,在此谢过
应该是Arrays.equals(a,b)
equals没有重写啊!!不是FALSE是什么!!
{
public static void main( String[] args )
{ int[] i1 = { 1, 2, 3, 4 };
int[] i2 = { 1, 2, 3, 4 };
boolean b = Arrays.equals( i1, i2 );
if( b )
{
System.out.println( "Same !" );
}
else
{
System.out.println( "Different !" );
}
}
}