Main Tutorials

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

  1. BigInteger JavaDoc
  2. Quora – What are the limits of String Size and BigInteger in Java?

About Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments