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


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


Java中UUID类的nameUUIDFromBytes()方法通常用于基于指定的字节数组检索基于第三类型名称的UUID。这用作静态工厂方法。

用法:

public static UUID nameUUIDFromBytes(byte[] byte_name)

参数:此方法接受参数byte_name,该参数表示用于构造UUID的字节数组。


返回值:此方法返回从指定数组生成的UUID实例。

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

示例1:

// Java code to illustrate nameUUIDFromBytes() method 
  
import java.util.*; 
  
public class UUID_Demo { 
    public static void main(String[] args) 
    { 
  
        // Creating a byte array 
        byte[] byte_name 
            = { 50, 40, 30, 20, 10 }; 
  
        // Printing the byte[] 
        System.out.println("Specified byte array: "
                           + Arrays.toString(byte_name)); 
  
        // Creating an UUID from byte 
        UUID UU_ID 
            = UUID 
                  .nameUUIDFromBytes(byte_name); 
  
        // Displaying the UUID value 
        System.out.println("UUID value from byte: "
                           + UU_ID); 
    } 
}
输出:
Specified byte array: [50, 40, 30, 20, 10]
UUID value from byte: d66541c4-a9db-3308-8c67-bbf87dc0df8b

示例2:

// Java code to illustrate nameUUIDFromBytes() method 
  
import java.util.*; 
  
public class UUID_Demo { 
    public static void main(String[] args) 
    { 
  
        // Creating a byte array 
        byte[] byte_name 
            = { 10, 15, 1, 45, 13, 20, 71 }; 
  
        // Printing the byte[] 
        System.out.println("Specified byte array: "
                           + Arrays.toString(byte_name)); 
  
        // Creating an UUID from byte 
        UUID UU_ID 
            = UUID 
                  .nameUUIDFromBytes(byte_name); 
  
        // Displaying the UUID value 
        System.out.println("UUID value from byte: "
                           + UU_ID); 
    } 
}
输出:
Specified byte array: [10, 15, 1, 45, 13, 20, 71]
UUID value from byte: 15fe1179-e857-306b-ad67-b2388e006c8a


相关用法


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