简体   繁体   English

如何在java中将字符串转换为数字? 但我不是在寻找 hashCode,因为它不会给出唯一编号。 至少我想要同样的数学逻辑

[英]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.

相关问题 我正在编写一个程序来查找给定数字的阶乘中 3 的数量。 来自用户的输入是数字 - I am writing a program to find number of 3's in factorial of a given number. The input from the user is the number 我想按数字和符号“。”分割字符串。 在 java - I want to split string by number and symbol “.” in java Java组合函数具有较小的数量限制。 如何使用数学Big int? - Java combination function has a limit of small number. How to use math Big int? 当我在数组中将数字彼此相乘时,我得到一个负数。 我该如何纠正? - When I multiply the numbers by each other in an array I am getting a negative number. How do I correct this? 我想要一个接受数组,低数字,高数字的方法。 并返回一个只包含数字的数组 - I want a method that accepts an array, low number, high number. and returns an array with only numbers in between that 在目录Java ..want中的文本文件列表中查找字符串,以查找行号。 - Finding String in a list of text files in a directory Java ..want to locate line number. JAVA:没有得到我想要的小数位数 - JAVA: Am not getting the number of decimal points I want 如何在Java中将很大的String转换为数字 - How Do I convert very big String to number in Java 如何将数字(作为字符串)转换为Java中的字节数组? - How do I convert a number (as a String) to an array of bytes in Java? 如何检查 Java 字符串是否至少包含一个大写字母、小写字母和数字? - How do I check if a Java String contains at least one capital letter, lowercase letter, and number?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM