Home » Java programming language

Java Float class equals() method with example

Float class equals() method: Here, we are going to learn about the equals() method of Float class with its syntax and example.
Submitted by Preeti Jain, on October 04, 2019

Float class equals() method

  • equals() method is available in java.lang package.
  • equals() method is used to check equality or inequality of this Object against the given Object or in other words we can say this method is used to compare two objects.
  • equals() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
  • equals() method does not throw an exception at the time of comparing two Objects.


    public boolean equals(Object ob);


  • Object ob – represents the Object to compare with.

Return value:

The return type of this method is boolean, it returns a boolean value, if both objects are same it returns true, else it returns false.


// Java program to demonstrate the example 
// of boolean equals(Object ob) method of 
// Float class

public class EqualsOfFloatClass {
    public static void main(String[] args) {
        // Variables initialization
        Float ob1 = new Float(10.0f);
        Float ob2 = new Float(20.0f);

        // Display value1,value2 values
        System.out.println("ob1: " + ob1);
        System.out.println("ob2: " + ob2);

        // It compare two objects of Float type
        // by calling ob1.equals(ob2)
        boolean compare = ob1.equals(ob2);

        // Display result values
        System.out.println("ob1.equals(ob2): " + compare);

        if (compare == true)
            System.out.println("Both objects are equal");
            System.out.println("Both objects are not equal");


ob1: 10.0
ob2: 20.0
ob1.equals(ob2): false
Both objects are not equal


Comments and Discussions



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© some rights reserved.