[英]How to convert string to number in java ? But i am not looking for hashCode as it wont give unique number. at least i want math logic for same
Hi I want to convert string to some unique number in java.嗨,我想将字符串转换为 java 中的某个唯一数字。 Exmple: "Production-0-1" to 100021 "Process-23-30" to 12310 And all return number has to be unique.例如:"Production-0-1" to 100021 "Process-23-30" to 12310 并且所有返回编号必须是唯一的。 I dont wanted to use hashCode as they can return duplicate like "Aa" and "BB" has same has code.我不想使用 hashCode,因为它们可以返回重复项,例如“Aa”和“BB”具有相同的代码。 Let me know math logic to create this is no method available.让我知道创建这个的数学逻辑没有可用的方法。
String random = "Production-0-1";
String bi = new BigInteger(random.getBytes("UTF-8")).toString();
BigInteger numBig = new BigInteger(bi);
System.out.println(numBig);
Based on @markspace comments, I tried the following and every time it produces random unique number but beware if you have a very large String and a limited memory space then the output may go out of bound.根据@markspace 评论,我尝试了以下操作,每次它都会生成随机唯一数字,但请注意,如果您有一个非常大的字符串和有限的内存空间,那么输出可能会超出范围。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.