Java Array Compare AreEqual(double[] vector1, double[] vector2)

Here you can find the source of AreEqual(double[] vector1, double[] vector2)

Description

Use this method to check that two vectors have are the same, i.e.

License

Open Source License

Parameter

Parameter Description
vector1 The first vector
vector2 The second vector

Return

If the two vectors are mathematically equal, returns true. False otherwise.

Declaration

public static boolean AreEqual(double[] vector1, double[] vector2) 

Method Source Code

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

public class Main {
    /**/*from   w w  w  . jav a2  s . co m*/
     * Use this method to check that two vectors have are the same, i.e.
     * that they contain the same items in the same order (equal from a maths
     * perspective).
     * @param vector1 The first vector
     * @param vector2 The second vector
     * @return If the two vectors are mathematically equal, returns true. False otherwise.
     */
    public static boolean AreEqual(double[] vector1, double[] vector2) {

        try {
            CheckArrays(vector1, vector2);
        } catch (IllegalArgumentException ex) {
            return false;
        }

        for (int i = 0; i < vector2.length; i++) {
            if (vector1[i] != vector2[i])
                return false;
        }

        return true;
    }

    /**
     * Ensures that the size of two arrays is equal.
     * @param vector1 The first vector
     * @param vector2 The second vector
     * @throws IllegalArgumentException if vectors have different dimensions.
     */
    public static void CheckArrays(double[] vector1, double[] vector2) {
        if (vector1.length != vector2.length) {
            throw new IllegalArgumentException(
                    "The vectors have to be of the same size.");
        }
    }
}

Related

  1. areEqual(byte[] a, byte[] b)
  2. areEqual(byte[] a, byte[] b)
  3. areEqual(byte[] a, byte[] b)
  4. areEqual(byte[] a, byte[] b)
  5. areEqual(byte[] array1, byte[] array2)
  6. areEqual(final byte[] a, final byte[] b)
  7. areEqualBytes(byte[] b1, byte[] b2)
  8. areEqualPropPaths(String[] pp1, String[] pp2)
  9. areEquals(byte[] g1, byte[] g2)