Java中的即时equals()方法
可以使用equals()JavaInstant类中的方法确定两个Instant对象的相等性。此方法需要一个参数,即要比较的Instant。如果两个Instant对象相等,则返回true,否则返回false。
演示此程序如下
示例
import java.time.*;
import java.time.temporal.ChronoUnit;
public class Demo {
public static void main(String[] args) {
Instant i1 = Instant.parse("2019-01-13T16:10:35.00Z");
Instant i2 = Instant.parse("2019-01-13T16:10:35.00Z");
System.out.println("Instant object i1 is: " + i1);
System.out.println("Instant object i2 is: " + i2);
boolean flag = i1.equals(i2);
if(flag)
System.out.println("\nThe Instant objects are equal");
else
System.out.println("\nThe Instant objects are not equal");
}
}输出结果
Instant object i1 is: 2019-01-13T16:10:35Z Instant object i2 is: 2019-01-13T16:10:35Z The Instant objects are equal
现在让我们了解上面的程序。
显示两个即时对象i1和i2。使用equals()方法检查Instant对象是否相等。使用if语句显示方法的返回值。演示此代码段如下所示:
Instant i1 = Instant.parse("2019-01-13T16:10:35.00Z");
Instant i2 = Instant.parse("2019-01-13T16:10:35.00Z");
System.out.println("Instant object i1 is: " + i1);
System.out.println("Instant object i2 is: " + i2);
boolean flag = i1.equals(i2);
if(flag)
System.out.println("\nThe Instant objects are equal");
else
System.out.println("\nThe Instant objects are not equal");热门推荐
1 带狗狗训练
4 听力训练狗狗
6 怎训练狗狗
7 腹肌训练狗狗
8 网球训练狗狗
9 记叙文训练狗狗
10 狗狗太凶怎么训练
11 核心力量训练狗狗
12 狗狗乱叫怎么训练
13 发音训练狗狗
14 怎么训练狗狗叼东西给主人
15 荆州训练狗狗
16 篮球训练狗狗
17 做训练狗狗
18 训练狗狗坐姿