Java中UUID類的equals()方法用於檢查一個UUID與另一個UUID是否相等。如果兩個UUID一點一點地完全相同,則該方法返回True。
用法:
public boolean equals(Object uuidObj)
參數:該方法采用一個參數uuidObj與UUID_1進行比較。
返回值:如果兩個UUID都相同,則該方法返回true,否則返回false。
以下示例程序旨在說明equals()方法的用法:
示例1:
// Java code to illustrate equals() method
import java.util.*;
public class UUID_Demo {
public static void main(String[] args)
{
// Creating two UUIDs
UUID UUID_1
= UUID
.fromString(
"5fc03087-d265-11e7-b8c6-83e29cd24f4c");
UUID UUID_2
= UUID
.fromString(
"5fc03087-d265-11e7-b8c6-83e29cd24f4c");
// Displaying the UUID values
System.out.println("UUID_1: "
+ UUID_1.clockSequence());
System.out.println("UUID_2: "
+ UUID_2.clockSequence());
// Comparing both the UUIDs
System.out.println("Are both UUID equal: "
+ UUID_1.equals(UUID_2));
}
}
輸出:
UUID_1: 14534 UUID_2: 14534 Are both UUID equal: true
示例2:
// Java code to illustrate equals() method
import java.util.*;
public class UUID_Demo {
public static void main(String[] args)
{
// Creating two UUIDs
UUID UUID_1
= UUID
.fromString(
"5fc03087-d265-11e7-b8c6-83e29cd24f4c");
UUID UUID_2
= UUID
.fromString(
"58e0a7d7-eebc-11d8-9669-0800200c9a66");
// Displaying the UUID values
System.out.println("UUID_1: "
+ UUID_1.clockSequence());
System.out.println("UUID_2: "
+ UUID_2.clockSequence());
// Comparing both the UUIDs
System.out.println("Are both UUID equal: "
+ UUID_1.equals(UUID_2));
}
}
輸出:
UUID_1: 14534 UUID_2: 5737 Are both UUID equal: false
相關用法
- Java UUID node()用法及代碼示例
- Java UUID hashCode()用法及代碼示例
- Java UUID timestamp()用法及代碼示例
- Java UUID clockSequence()用法及代碼示例
- Java UUID compareTo()用法及代碼示例
- Java UUID toString()用法及代碼示例
- Java UUID getLeastSignificantBits()用法及代碼示例
- Java UUID variant()用法及代碼示例
- Java UUID fromString()用法及代碼示例
- Java UUID version()用法及代碼示例
- Java UUID nameUUIDFromBytes()用法及代碼示例
- Java UUID getMostSignificantBits()用法及代碼示例
- Java Map equals()用法及代碼示例
- Java Set equals()用法及代碼示例
- Java NumberFormat equals()用法及代碼示例
注:本文由純淨天空篩選整理自Chinmoy Lenka大神的英文原創作品 UUID equals() Method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。