Java Integer Array Create intArrayEquals(int[] a1, int[] a2)

Here you can find the source of intArrayEquals(int[] a1, int[] a2)

Description

Compare two int arrays for equality

License

Open Source License

Parameter

Parameter Description
a1 the a1
a2 the a2

Return

true, if they are equal (both null is considered equal)

Declaration

public static boolean intArrayEquals(int[] a1, int[] a2) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*from ww w . j a  v  a 2s  .  c om*/
     * Compare two int arrays for equality
     *
     * @param a1 the a1
     * @param a2 the a2
     * @return true, if they are equal (both null is considered equal)
     */
    public static boolean intArrayEquals(int[] a1, int[] a2) {
        return intArrayEquals(a1, 0, a2, 0, a1 == null ? 0 : a1.length);
    }

    /**
     * Compare two int arrays for equality
     *
     * @param a1 the a1
     * @param a1Pos starting compare source index
     * @param a2 the a2
     * @param a2Pos starting compare dest index
     * @param length the length
     * @return true, if successful
     */
    @SuppressWarnings("null")
    public static boolean intArrayEquals(int[] a1, int a1Pos, int[] a2,
            int a2Pos, int length) {
        if (a1 == null && a2 != null)
            return false;
        if (a2 == null && a1 != null)
            return false;
        if (a1 == null)
            return true;
        if (a1.length < a1Pos + length)
            return false;
        if (a2.length < a2Pos + length)
            return false;
        for (int i = a1Pos, j = a2Pos; i < length; i++, j++) {
            if (a1[i] != a2[j])
                return false;
        }
        return true;
    }
}

Related

  1. intArray(Integer... values)
  2. intArray(String data)
  3. intArrayConcat(int[] a, int[] b)
  4. intArrayContains(int val, int[] array)
  5. intArrayContains(int[] array, int key)
  6. intArrayFromString(final String data)
  7. intArrayFromString(String record)
  8. intArrayMin(int[] arr)
  9. intArraysAreEqual(int array1[], int array2[])