Skip to content
Related Articles

Related Articles

Improve Article
Level equals() method in Java with Examples
  • Last Updated : 14 Oct, 2019

The equals() method of java.util.logging.Level is used to check if this level object is equals to passed object or not.If both objects are equals then method will return true else false.

Syntax:

public boolean equals(Object ox)

Parameters: This method accepts an object ox which is the reference object with which to compare.

Return: This method returns true if and only if the two objects have the same level value.

Below programs illustrate equals() method:
Program 1:






// Java program to illustrate equals() method
  
import java.util.logging.Level;
import java.util.logging.Logger;
  
public class GFG {
  
    public static void main(String[] args)
    {
  
        // Create a Logger
        Logger logger
            = Logger.getLogger(
                        Object.class.getName())
                  .getParent();
  
        // Get level of logger
        Level level1
            = logger.getLevel();
  
        // Create a second Logger
        Logger logger2
            = Logger.getLogger(
                        String.class.getName())
                  .getParent();
  
        // Get level of second logger
        Level level2
            = logger2.getLevel();
  
        // apply equal method
        boolean value = level1.equals(level2);
  
        // print level names
        System.out.println("Both level are equal = "
                           + value);
    }
}
Output:
Both level are equal = true

Program 2:




// Java program to illustrate equals() method
  
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
  
public class GFG {
  
    public static void main(String[] args)
    {
  
        // Create a Logger
        Logger logger
            = Logger.getLogger(
                        Object.class.getName())
                  .getParent();
  
        // Get level of logger
        Level level1
            = logger.getLevel();
  
        // Create a second Logger for ArrayList class
        Logger logger2
            = Logger.getLogger(
                ArrayList.class.getName());
  
        // Get level of second logger
        Level level2
            = logger2.getLevel();
  
        // apply equal method
        boolean value = level1.equals(level2);
  
        // print level names
        System.out.println("Both level are equal = "
                           + value);
    }
}
Output:
Both level are equal = false

References: https://docs.oracle.com/javase/10/docs/api/java/util/logging/Level.html#equals(java.lang.Object)

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.




My Personal Notes arrow_drop_up
Recommended Articles
Page :