如何截断两个uuid并在scala中生成新的uuid

时间:2015-12-24 06:54:02

标签: java scala

例如:

  val uuid1 = UUID.fromString("38400000-8cf0-11bd-b23e-10b96e4ef00d")
  val uuid2 = UUID.fromString("475c4380-a8a4-11e5-c000-000000000000") 

我的输出应该是两者的组合。

 output =   475c4380-a8a4-11e5 + b23e-10b96e4ef00d = 475c4380-a8a4-11e5-b23e-10b96e4ef00d

2 个答案:

答案 0 :(得分:0)

如果你有两个UUID,你需要将它们转换为字符串,获取子字符串,然后创建一个新的UUID:

output = UUID.fromString( uuid1.toString.substring(0,18) + uuid2.toString.substring(19) )

答案 1 :(得分:0)

最简单的方法就是使用UUID实现并构建一个新的uuid

  val uuid1 = UUID.fromString("38400000-8cf0-11bd-b23e-10b96e4ef00d")
  val uuid2 = UUID.fromString("475c4380-a8a4-11e5-c000-000000000000")

  println( new UUID(uuid2.getMostSignificantBits, uuid1.getLeastSignificantBits).toString )