A few days ago, you need to do a number-type database primary key processing, and there are 38 bits. So what rules can you use to control uniqueness. Finally decided to adopt the time, the month and the second millisecond, plus random number.
The problem arises, how to convert a 38-bit numeric string into an integer type and store it in a database. The default long type, and the maximum value is only 19 digits. What to do.
The solution is as follows:
Use BigInteger type
package numeric string;
Import Java.math.BigInteger;
public class Test {public
static void Main (string[] args) {
//long type Max only 19-bit
Long MaxL = long.max_value;
String max2 = "12345678901234567890123456789012345678";
System.out.println (MAX2);
System.out.println (MaxL); System.out.println (Long.parselong (MAX2)),//throw anomaly
biginteger maxint = new BigInteger (MAX2);
System.out.println (maxint);
}
Run results