Arrays class equals() method

  • Using the equals method under Arrays cannot determine whether the contents of two two-dimensional arrays are equal, but you can determine whether two one-dimensional arrays are equal
import java.util.Arrays;

public class ArrayDemo02 {
    
    
    public static void main(String[] args) {
    
    
        int[] array =new int[10];
        array[2] = 12;
        int[] array1 =new int[10];
        array1[2] = 12;
        System.out.println("一维数组array是否与一维数组array1相等? :"+Arrays.equals(array,array1));
        int[][] num = new int[10][10];
        num[2][0] =12;
        int[][] num1 = new int[10][10];
        num1[2][0] =12;
        System.out.println("二维数组num是否与二维数组num2相等? :"
                + Arrays.equals(num, num1));
    }
}

Results of the:
Insert picture description here

Guess you like

Origin blog.csdn.net/qq_41017444/article/details/112724902