1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
/* Compare Two Java float Arrays Example This java example shows how to compare two float arrays for equality using Arrays.equals method. */ import java.util.Arrays; public class CompareFloatArraysExample { public static void main(String[] args) { //create float arrays float[] floatArray1 = new float[]{459.432f,348.43f,5832.327f}; float[] floatArray2 = new float[]{459.432f,348.43f,5832.327f}; /* To compare two float arrays use, static boolean equals(float array1[], float array2[]) method of Arrays class. It returns true if both arrays are equal. Arrays are considered as equal if they contain same elements in same order. Two float elements are considered as equal if new Float(d1).equals(new Float(d2)) */ boolean blnResult = Arrays.equals(floatArray1,floatArray2); System.out.println("Are two float arrays equal ? : " + blnResult); /* Please note that two float array references pointing to null are considered as equal. Also, two NaN values are considerd equal. But 0.0f and -0.0f are considered as unequal. */ } } /* Output of the program would be Are two float arrays equal ? : true */ |
Add Comment