Java Arrays equals方法


Java Arrays equals方法

package com.codingdict;

import java.util.Arrays;

public class ArrayDemo {
   public static void main(String[] args) {

      // initializing three short arrays
      short[] arr1 = new short[] { 2, 12, 15, 6 };
      short[] arr2 = new short[] { 4, 1, 15, 6 };
      short[] arr3 = new short[] { 3, 1, 6, 12 };

      // comparing arr1 and arr2
      boolean retval=Arrays.equals(arr1, arr2);
      System.out.println("arr1 and arr2 equal: " + retval);

      // comparing arr2 and arr3
      boolean retval2=Arrays.equals(arr2, arr3);
      System.out.println("arr2 and arr3 equal: " + retval2);
   }
}