當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Java UUID clockSequence()用法及代碼示例


Java中UUID類的clockSequence()方法通常用於了解與此UUID相關聯的時鍾序列值。此UUID的時鍾序列字段用於創建14位時鍾序列值。

用法:

public int clockSequence()

參數:此方法不帶任何參數。


返回值:此方法返回一個int值,該值是與此UUID關聯的時鍾序列值。

異常:如果此UUID不是版本1 UUID,則該方法引發UnsupportedOperationException。

以下示例程序旨在說明clockSequence()方法的用法:

示例1:

// Java code to illustrate clockSequence() method 
  
import java.util.*; 
  
public class UUID_Demo { 
    public static void main(String[] args) 
    { 
  
        // Creating two UUIDs 
        UUID UUID_1 
            = UUID 
                  .fromString( 
                      "58e0a7d7-eebc-11d8-9669-0800200c9a66"); 
  
        // Displaying the UUID 
        System.out.println("UUID: "
                           + UUID_1); 
  
        // Displaying the clock sequence value 
        System.out.println("The clock sequence value is: "
                           + UUID_1.clockSequence()); 
    } 
}
輸出:
UUID: 58e0a7d7-eebc-11d8-9669-0800200c9a66
The clock sequence value is: 5737

示例2:

// Java code to illustrate clockSequence() 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"); 
  
        // Displaying the UUID 
        System.out.println("UUID: "
                           + UUID_1); 
  
        // Displaying the variant Value 
        System.out.println("The clock sequence value is: "
                           + UUID_1.clockSequence()); 
    } 
}
輸出:
UUID: 5fc03087-d265-11e7-b8c6-83e29cd24f4c
The clock sequence value is: 14534


相關用法


注:本文由純淨天空篩選整理自Chinmoy Lenka大神的英文原創作品 UUID clockSequence() Method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。