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
相關用法
- Java UUID equals()用法及代碼示例
- Java UUID fromString()用法及代碼示例
- Java UUID compareTo()用法及代碼示例
- Java UUID getMostSignificantBits()用法及代碼示例
- Java UUID clockSequence()用法及代碼示例
- Java UUID getLeastSignificantBits()用法及代碼示例
- Java UUID timestamp()用法及代碼示例
- Java UUID hashCode()用法及代碼示例
- Java UUID node()用法及代碼示例
- Java UUID version()用法及代碼示例
- Java UUID toString()用法及代碼示例
- Java UUID variant()用法及代碼示例
- Java Java.util.UUID用法及代碼示例
- Java Java lang.Long.numberOfLeadingZeros()用法及代碼示例
- Java Java lang.Long.reverse()用法及代碼示例
注:本文由純淨天空篩選整理自Chinmoy Lenka大神的英文原創作品 UUID nameUUIDFromBytes() Method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。