Java Array Equal arraysAreEqual(double[] a1, double[] a2)

Here you can find the source of arraysAreEqual(double[] a1, double[] a2)

Description

Compare two double arrays and return true if both not null, and are of equal length and contain equal values.

License

Open Source License

Parameter

Parameter Description
a1 first array
a2 second array

Return

true if equal

Declaration

static public boolean arraysAreEqual(double[] a1, double[] a2) 

Method Source Code

//package com.java2s;

public class Main {
    /**//ww w  .  j  a  va  2 s.co  m
     * <p>Compare two double arrays and return true if both not null, and are of equal length and contain equal values.</p>
     *
     * @param   a1   first array
     * @param   a2   second array
     * @return      true if equal
     */
    static public boolean arraysAreEqual(double[] a1, double[] a2) {
        //System.err.println("ArrayCopyUtilities.arraysAreEqual(): a1 = "+a1);
        //System.err.println("ArrayCopyUtilities.arraysAreEqual(): a2 = "+a2);
        boolean result = true;
        if (a1 == null || a2 == null || a1.length != a2.length) {
            result = false;
        } else {
            for (int i = 0; i < a1.length; ++i) {
                //if (a1[i] != a2[i]) {
                if (Math.abs(a1[i] - a2[i]) > 0.000001) {
                    result = false;
                    break;
                }
            }
        }
        //System.err.println("ArrayCopyUtilities.arraysAreEqual(): "+result);
        return result;
    }
}

Related

  1. arrayEquals(Object[] source, Object target)
  2. arrayEquals(String[] array1, String[] array2)
  3. arrayEquals(String[] targetMethodParamTypes, String[] paramTypes)
  4. arrayEqualsExceptNull(Object[] a1, Object[] a2)
  5. arrayEqualsSubset(final byte[] array, final int... elements)
  6. arraysAreEqual(final byte[] array1, final byte[] array2)
  7. arraysAreEqual(Object value, Object otherValue)
  8. arraysEqual(boolean[] a, boolean[] b)
  9. arraysEqual(byte array1[], byte array2[])