1// Primitive int
2int myInt = 10
3BigInteger bigInt = BigInteger.valueOf(myInt);
4// Integer object
5Integer integer = Integer.valueOf(myInt);
6BigInteger bigInt = BigInteger.valueOf(myInteger.intValue());
7bigInt = BigInteger.valueOf(myInteger); // works too
1The java.math.BigInteger.compareTo(BigInteger value) method
2Compares this BigInteger with the BigInteger passed as the parameter.
3
4________________________________________
5import java.math.BigInteger;
6
7public class GFG {
8
9 public static void main(String[] args)
10 {
11 // Creating 2 BigInteger objects
12 BigInteger b1, b2;
13
14 b1 = new BigInteger("321456");
15 b2 = new BigInteger("321456");
16
17 // apply compareTo() method
18 int comparevalue = b1.compareTo(b2);
19
20 // print result
21 if (comparevalue == 0) {
22
23 System.out.println("BigInteger1 "
24 + b1 + " and BigInteger2 "
25 + b2 + " are equal");
26 }
27 else if (comparevalue == 1) {
28
29 System.out.println("BigInteger1 " + b1 + "
30 is greater than BigInteger2 " + b2);
31 }
32 else {
33
34 System.out.println("BigInteger1 " + b1 + "
35 is lesser than BigInteger2 " + b2);
36 }
37 }
38}
39
40