JAVA:比较两个数组

  • Post author:
  • Post category:java


public class 比较两个数组 {
    public static void main(String[] args) {
        int[] arr1 = {112,2424,545,646};
        int[] arr2 = {112,2424,545,646};
        boolean num = num(arr1,arr2);
        System.out.println(num);
    }

    public static boolean num(int[] arr1, int[] arr2) {
        //1、比较长度
        if(arr1.length != arr2.length){
            return false;
        }
        //2、比较数组中的元素内容
        for (int i = 0;i< arr1.length;i++){
            if(arr1[i] != arr2[i]){
                return false;
            }
        }
        return true;
    }
}



版权声明:本文为qq_50395700原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。