Common Array Algorithms

25. Various equals() Methods


Answer:

A: NOT Equal

    The two arrays are different lengths.

B: NOT Equal

    The elements are not in the same order.

C: Equal

    The array is compared with itself, and found to equal.

Various equals() Methods

The method used in the above examples is this:

static boolean Array.equals( int[] a, int[] a2 )

The class Arrays has a variety of equals() methods to handle different types. But in all cases, both arrays are of the same type.

static boolean 	equals(boolean[] a, boolean[] a2)

static boolean equals(byte[] a, byte[] a2)

static boolean equals(char[] a, char[] a2)

static boolean equals(double[] a, double[] a2)

static boolean equals(float[] a, float[] a2)

static boolean equals(int[] a, int[] a2)

static boolean equals(long[] a, long[] a2)

static boolean equals(Object[] a, Object[] a2)

static boolean equals(short[] a, short[] a2)

Question 25:

Could you write your own equals() method.