{

BigInteger multiply method in Java with examples


This post shows how to multiply BigIntegers in java with examples. use multiplication(*) operator for multiply biginteger in java.

You can also check my previous posts on the BigInteger class in java.

The same does not work for BigInteger objects. It gives compilation error Operator ‘*’ cannot be applied to ‘java.math.BigInteger’, ‘java.math.BigInteger’.

Here is an example using the multiplication operator

import java.math.BigInteger;

public class BigIntegerMultiply {
    public static void main(String[] args) {
        BigInteger operand1= BigInteger.valueOf(2);
        BigInteger operand2= BigInteger.valueOf(2);
        BigInteger result=operand1*operand2;
        System.out.println(result);
    }
}

It provides a multiply method to do multiplication on BigInteger.

Java BigInteger multiply method with example

The multiply method returns the result of the multiplication of values.

BigInteger is immutable and the result of methods always returns a new object.

It internally uses an array of integers to do the process, The performance is less compared with Integer multiplication.

Syntax:

    public BigInteger multiply(BigInteger val) 
import java.math.BigInteger;

public class BigIntegerMultiply {
    public static void main(String[] args) {
        BigInteger operand1= BigInteger.valueOf(212312);
        BigInteger operand2= BigInteger.valueOf(2123);
        BigInteger result=operand1.multiply(operand2);
        System.out.println(result);
    }
}

Output:

450738376
THE BEST NEWSLETTER ANYWHERE
Join 6,000 subscribers and get a daily digest of full stack tutorials delivered to your inbox directly.No spam ever. Unsubscribe any time.

Similar Posts
Subscribe
You'll get a notification every time a post gets published here.





Related posts

BigInteger divide method in Java with examples| BigDecimal divide tutorials

How to Check whether Bigdecimal value is zero or not in Java

How to Convert BigDecimal to Double or Double to BigDecimal in java with examples

How to Convert BigDecimal to Float or Float to BigDecimal in java with examples

How to get yesterday and tomorrow date in java with example

How to Rounding Bigdecimal values with 2 Decimal Places in Java

Multiple ways to fix java.util.NoSuchElementException: No value present error in java