Java – How to convert int to BigInteger?

In Java, we can use BigInteger.valueOf(int) to convert int to a BigInteger JavaExample.java package com.mkyong; import java.math.BigInteger; public class JavaExample { public static void main(String[] args) { int n = 100; System.out.println(n); // convert int to Integer Integer integer = Integer.valueOf(n); System.out.println(integer); // convert int to BigInteger BigInteger bigInteger = BigInteger.valueOf(n); System.out.println(bigInteger); // convert Integer …

Read more

Java – Find the length of BigInteger?

In Java, we can convert the BigInteger to a String object and get the length of the String. JavaExample.java package com.mkyong; import java.math.BigInteger; public class JavaExample { public static void main(String[] args) { BigInteger bigInteger = BigInteger.valueOf(100000000000000000L); //18 System.out.println(bigInteger.toString().length()); } } Output 18 References BigInteger JavaDoc Quora – What are the limits of String Size …

Read more