Compare Two Java float Arrays Example

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

Visit Java Example Forums to request Java examples or ask Java questions!
OR
Try out our new Java Search Engine




Suggested Reading

Oracle Magazine
Contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more.
Cost: FREE

View/Subscribe
NASA Tech Briefs
Features exclusive reports of innovations developed by NASA and its industry partners/contractors that can be applied to develop new/improved products and solve engineering or manufacturing problems.
Cost: FREE

View/Subscribe
FierceBiotech IT
Is a free, easy to read weekly email service that brings must read biotech IT news to senior biotech, pharma, and IT executives.
Cost: FREE

View/Subscribe
Simply SQL
Simply SQL is a practical step-by-step guide to writing SQL.
Cost: FREE

View/Subscribe
Simply JavaScript
Packed with full-color examples, Simply JavaScript is all you need to start programming in JavaScript the right way.
Cost: FREE

View/Subscribe
PCMag.com's What's New Now
Lance Ulanoff, Editor in Chief of the PC Magazine Network, brings you this twice-weekly roundup of the latest top tech stories, the best new product reviews, plus special offers from Ziff Davis and its partners.
Cost: FREE

View/Subscribe

Could not find what you are looking for? Search Java Examples




Feel Tired? Read Jokes & Inspirational Stories, Play Games!