集册 Java实例教程 比较数组

比较数组

欢马劈雪     最近更新时间:2020-01-02 10:19:05

591
比较数组

import java.util.Arrays;


public class Main {

/* from 
N o w J a v a . c o m*/

  public static void main(String[] argv) {

    // null arrays are equal

    boolean[] bArr1 = null;

    boolean[] bArr2 = null;

    boolean b = Arrays.equals(bArr1, bArr2);


    // Compare two boolean arrays

    bArr1 = new boolean[] { true, false };

    bArr2 = new boolean[] { true, false };/*nowjava.com - 时代Java 提供*/

    b = Arrays.equals(bArr1, null); 

    b = Arrays.equals(bArr1, bArr2); 


    // There are equals() methods for all eight primitive types

    b = Arrays.equals(new byte[] { 0 }, new byte[] { 0 }); 

    b = Arrays.equals(new char[] { 'a' }, new char[] { 'a' }); 

    b = Arrays.equals(new short[] { 0 }, new short[] { 0 }); 

    b = Arrays.equals(new int[] { 0 }, new int[] { 0 }); 

    b = Arrays.equals(new long[] { 0L }, new long[] { 0L }); 

    b = Arrays.equals(new float[] { 0F }, new float[] { 0F }); 

    b = Arrays.equals(new double[] { 0D }, new double[] { 0D }); 


    // When comparing Object arrays, null elements are equal.

    // If the elements are not null, Object.equals() is used.

    b = Arrays.equals(new 
展开阅读全文