📜  Java中的级别 equals() 方法和示例

📅  最后修改于: 2022-05-13 01:55:42.129000             🧑  作者: Mango

Java中的级别 equals() 方法和示例

Java.util.logging.Levelequals()方法用于检查此级别对象是否等于传递的对象。如果两个对象相等,则该方法将返回 true 否则返回 false。

句法:

public boolean equals(Object ox)

参数:此方法接受一个对象 ox,它是要与之比较的参考对象。

Return :当且仅当两个对象具有相同的级别值时,此方法才返回 true。

下面的程序说明了 equals() 方法:
方案一:

// 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);
    }
}
输出:
Both level are equal = true

方案二:

// 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);
    }
}
输出:
Both level are equal = false

参考资料: https: Java Java.lang.Object)