Level equals() method in Java with Examples

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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);
    }
}

chevron_right


Output:

Both level are equal = true

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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);
    }
}

chevron_right


Output:

Both level are equal = false

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



My Personal Notes arrow_drop_up

I am a Developer I love to code and bring my ideas alive

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.