BigInteger can be bigger than Long. If so, then the ".longValue()" will return an exception.
/**
* @author lautturi.com
* Java example: convert biginteger to long in java
*/
import java.math.BigInteger;
import java.util.*;
public class Lautturi {
public static void main(String[] args) {
BigInteger bigInteger = new BigInteger(Long.MAX_VALUE + "");
Long l = bigInteger.longValue();
System.out.println("BigIntegerValue: " + bigInteger);
System.out.println("LongValue: " + bigInteger.longValue());
}
}
output:
BigIntegerValue: 9223372036854775807 LongValue: 9223372036854775807