判断两个数组内容是否相同

private static boolean isMatched(int[] a,int[] b){
        if(a==b){
            return true;
        }
        if (a==null || b==null){
            return false;
        }
        if(a.length!=b.length){
            return false;
        }
        //内部循环的起点
        int nextIndex= 0;
        for(int i=0;i<a.length;i++){
            boolean next= false;
            for(int j=nextIndex;j<b.length;j++){
                //如果找到匹配的
                if(a[i]==b[j]){
                    //记录下次的索引位置,避免无用的循环以及提高匹配的准确性
                    nextIndex= j+1;
                    next= true;
                    break;
                }
            }
            //如果一次循环匹配结束没有找到匹配项,则说明两个数组不相等
            if(!next){
                return false;
            }
        }
        //如果执行到这里,说明全部匹配
        return true;
    }

 比较的数组顺序无关,只有内容匹配返回true;

原文地址:https://www.cnblogs.com/hihtml5/p/6517219.html