Java Arrays - equals() Method
The java.util.Arrays.equals() method is used to check whether the two specified arrays of floats are equal or not. It returns true if the two arrays are equal, else returns false. The two arrays are considered equal if they contain the same elements in the same order.
Syntax
public static boolean equals(float[] a, float[] b)
Parameters
a |
Specify the first array to be tested for equality. |
b |
Specify the second array to be tested for equality. |
Return Value
Returns true if the two arrays are equal, else returns false.
Exception
NA.
Example:
In the example below, the java.util.Arrays.equals() method is used to check whether the two arrays of floats are equal or not.
import java.util.*; public class MyClass { public static void main(String[] args) { //creating three float arrays float Arr1[] = {10.1f, 2.6f, -3.6f, 35f, 56f}; float Arr2[] = {10.1f, 2.6f, -3.6f, 35f, 56f}; float Arr3[] = {10f, 2f, -3f, 35f, 56f}; //check Arr1 and Arr2 for equality boolean result1 = Arrays.equals(Arr1, Arr2); System.out.print("Are Arr1 and Arr2 equal?: "+ result1); //check Arr1 and Arr3 for equality boolean result2 = Arrays.equals(Arr1, Arr3); System.out.print("\nAre Arr1 and Arr3 equal?: "+ result2); } }
The output of the above code will be:
Are Arr1 and Arr2 equal?: true Are Arr1 and Arr3 equal?: false
❮ Java.util - Arrays