java.util.logging.Level的equals()方法用于检查此级别的对象是否等于传递的对象。如果两个对象相等,则方法将返回true,否则返回false。
用法:
public boolean equals(Object ox)
参数:此方法接受对象ox,它是要与之进行比较的参考对象。
返回:仅当两个对象具有相同的级别值时,此方法返回true。
以下示例程序旨在说明equals()方法:
示例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);
}
}
输出:
Both level are equal = true
示例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);
}
}
输出:
Both level are equal = false
参考文献: https://docs.oracle.com/javase/10/docs/api/java/util/logging/Level.html#equals(java.lang.Object)
相关用法
- Java Map equals()用法及代码示例
- Java Set equals()用法及代码示例
- Java ZonedDateTime equals()用法及代码示例
- Java NumberFormat equals()用法及代码示例
- Java LocalTime equals()用法及代码示例
- Java UUID equals()用法及代码示例
- Java Locale equals()用法及代码示例
- Java Optional equals()用法及代码示例
- Java Byte equals()用法及代码示例
- Java Short equals()用法及代码示例
- Java SimpleDateFormat equals()用法及代码示例
- Java LocalDateTime equals()用法及代码示例
- Java OffsetTime equals()用法及代码示例
- Java OptionalDouble equals()用法及代码示例
- Java OptionalLong equals()用法及代码示例
注:本文由纯净天空筛选整理自AmanSingh2210大神的英文原创作品 Level equals() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。