当一个数字非常大时,则肯定无法用基本类型接收,所以最早碰到大数字时往往会使用String类进行接收,然后再采用String类进行接收,然后再采用拆分的方式进行计算,但操作非常麻烦,所以在Java中为了解决这样的难题提供了BigInteger类。BigInteger类表示大整数类,定义在java.math包中,如果在操作时一个整数数据已经超过了最大的类型长度long(64bit),数据就无法装入,此时可以使用BigInteger类进行操作。
实例:
public
static
void
testBigInteger(){
Integer one=1223455;
BigInteger two=
new
BigInteger(
"123456789123456789"
);
BigInteger three=
new
BigInteger(
"1"
);
three=two.add(three );
System.
out
.println(three);
}