Java中的工期equals()方法
可以使用equals()Java中Duration类中的方法确定两个持续时间的相等性。该方法需要一个参数,即要比较的持续时间。同样,如果两个持续时间相等,则返回true,否则返回false。
演示此的程序如下所示-
示例
import java.time.Duration;
public class GFG {
public static void main(String[] args) {
Duration d1 = Duration.ofDays(1);
Duration d2 = Duration.ofHours(24);
boolean flag = d1.equals(d2);
if(flag)
System.out.println("The durations are equal");
else
System.out.println("The durations are not equal");
}
}输出结果
The durations are equal
现在让我们了解上面的程序。
使用方法比较两个持续时间equals(),并将返回值存储在标志中。然后显示持续时间是否相等。演示这的代码片段如下-
Duration d1 = Duration.ofDays(1);
Duration d2 = Duration.ofHours(24);
boolean flag = d1.equals(d2);
if(flag)
System.out.println("The durations are equal");
else
System.out.println("The durations are not equal");热门推荐
10 财运虎年祝福语简短语
11 单亲爸爸春节祝福语简短
12 狗狗上厕所训练
13 植物种植祝福语简短
14 翻译考试祝福语朋友简短
15 个人周年庆简短祝福语
16 狗狗怎么训练
17 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短