Wednesday, July 3, 2024
HomeLanguagesJavaLevel equals() method in Java with Examples

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:




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

Nokonwaba Nkukhwana
Experience as a skilled Java developer and proven expertise in using tools and technical developments to drive improvements throughout a entire software development life cycle. I have extensive industry and full life cycle experience in a java based environment, along with exceptional analytical, design and problem solving capabilities combined with excellent communication skills and ability to work alongside teams to define and refine new functionality. Currently working in springboot projects(microservices). Considering the fact that change is good, I am always keen to new challenges and growth to sharpen my skills.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments