Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Java BigInteger to String

In this tutorial, we will see how to convert Biginteger to String in java.

There are many ways to convert BigInteger to String in java.Some of them are:

  • Using toString()
  • Using String.valueOf()

toString method

We can simply use BigInteger’s toString method to convert BigInteger to String.

package org.arpit.java2blog;

import java.math.BigInteger;

public class BigIntegerToStringMain {

	public static void main(String[] args) {
		BigInteger bigInteger=new BigInteger("25");
		String toStringBigInteger=bigInteger.toString();
		System.out.println(toStringBigInteger);
	}
}

When you run above program, you will get below output:

25

String’s ValueOf method

We can also use String’s ValueOf() method to convert BigInteger to String but it interanally uses BigInteger’s toString method only, so it is better to use BigInteger’s toString method

package org.arpit.java2blog;

import java.math.BigInteger;

public class BigIntegerToStringMain {

	public static void main(String[] args) {
		BigInteger bigInteger=new BigInteger("43");
		String valueOfBigInteger=String.valueOf(bigInteger);
		System.out.println(valueOfBigInteger);
	}
}

When you run above program, you will get below output:

43

That’s all about BigInteger to String conversion.

The post Java BigInteger to String appeared first on Java2Blog.



This post first appeared on How To Learn Java Programming, please read the originial post: here

Share the post

Java BigInteger to String

×

Subscribe to How To Learn Java Programming

Get updates delivered right to your inbox!

Thank you for your subscription

×