- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check two float arrays for equality in Java
To check two float arrays for equality, use the Arrays.equals() method.
In our example, we have the following two float arrays.
float[] floatVal1 = new float[] { 3.2f, 5.5f, 5.3f }; float[] floatVal2 = new float[] { 3.2f, 5.5f, 5.3f };
Let us now compare them for equality.
if (Arrays.equals(floatVal1, floatVal2)) { System.out.println("Both are equal!"); }
The following is an example wherein we compare arrays and with that also use == to check for other conditions.
Example
import java.util.Arrays; public class Demo { public static void main(String args[]) { float[] floatVal1 = new float[] { 3.2f, 5.5f, 5.3f }; float[] floatVal2 = new float[] { 3.2f, 5.5f, 5.3f }; if (floatVal1 == null) { System.out.println("First array is null!"); } if (floatVal2 == null) { System.out.println("Second array is null!"); } if (floatVal1.length != floatVal2.length) { System.out.println("Both does not have equal number of elements!"); } if (Arrays.equals(floatVal1, floatVal2)) { System.out.println("Both are equal!"); } } }
Output
Both are equal!
- Related Articles
- Check two ArrayList for equality in Java
- Check two HashMap for equality in Java
- Check two numbers for equality in Java
- How to compare two arrays for equality in Perl?
- Java Program to compare Two Java float Arrays
- Equality of two arrays JavaScript
- Java Program to check for equality between two strings ignoring the case
- Compare two float arrays in a single line in Java
- Equality of two 2-D arrays - JavaScript
- How to compare two ArrayList for equality in Java?
- Program to test the equality of two arrays - JavaScript
- How to check a String for palindrome using arrays in java?
- How to compare two lists for equality in C#?
- Java Program to compare strings for equality
- Java Program to Check if two Arrays are Equal or not

Advertisements