当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java UUID variant()用法及代码示例


每个UUID都有一个变体编号,描述此UUID的生成。 Java中UUID类的variant()方法通常用于获取与此UUID关联的变体编号。

用法:

public int variant()

参数:此方法不带任何参数。


返回值:此方法返回一个int值,该值是与此UUID关联的变量号。

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

示例1:

// Java code to illustrate variant() 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 variant number 
        System.out.println("The variant number is: "
                           + UUID_1.variant()); 
    } 
}
输出:
UUID: 58e0a7d7-eebc-11d8-9669-0800200c9a66
The variant number is: 2

示例2:

// Java code to illustrate variant() 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 variant number is: "
                           + UUID_1.variant()); 
    } 
}
输出:
UUID: 5fc03087-d265-11e7-b8c6-83e29cd24f4c
The variant number is: 2


相关用法


注:本文由纯净天空筛选整理自Chinmoy Lenka大神的英文原创作品 UUID variant() Method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。