Home » Java » Java Reference

# Java BigInteger Class Methods

Java BigInteger class has the following built-in methods.

Method | Description |
---|---|

abs() | It is used to get the absolute value of this BigInteger. |

add() | It is used to add the given BigInteger (val) to this BigInteger [i.e. (this BigInteger) + (BigInteger val)]. |

and() | It is used to perform and operation between this BigInteger and the given BigInteger (val) [i.e. (this BigInteger) & (BigInteger val)]. |

andNot() | It is used to perform andNot operation between this BigInteger and the given BigInteger (val) [i.e. (this BigInteger) & (~BigInteger val)]. |

bitCount() | It is used to count the number of bits in 2's complement denotation of this BigInteger. |

bitLength() | It is used to return the number of bits in minimum 2's complement denotation of this BigInteger without including a sign bit. |

clearBit() | It is used to clear the set bit at the given indices from this BigInteger if exists. |

compareTo() | It is used to compare to this BigInteger object with the given object or in other words we can say this method it compares two objects of "BigInteger" type. |

divide() | It is used to divide this BigInteger by the given BigInteger (divsr) (i.e. this BigInteger / BigInteger ). |

divideAndRemainder() | Returns BigInteger array of 2 elements that contain quotient that is calculated by using (this BigInteger)/(BigInteger val) followed by the remainder that is calculated by using (this BigInteger) % (BigInteger val). |

doubleValue() | It is used to convert this BigInteger into a double and when this BigInteger value is large enough to fit in a long so it will be converted to either Double.POSITIVE_INFINITY or NEGATIVE_INFINITY. |

equals() | It is used to check whether this BigInteger and the given object are equal or not. |

flipBit() | It is used to flip the bit indexed at the given position in this BigInteger. |

floatValue() | It is used to convert this BigInteger into a float. |

gcd() | It is used to return the greatest common divisor of the absolute of this BigInteger and the given parameter (val). |

getLowestSetBit() | It is used to returns the index of 1's bit from the rightmost side in this BigInteger. |

hashCode() | It is used to return the hash code value of this BigInteger. |

intValue() | It is used to convert this BigInteger into an integer. |

isProbablePrime() | It is used to check whether this BigInteger is probable prime or not. |

longValue() | It is used to convert this BigInteger into a long. |

max() | It is used to get the highest value from both of the compared object (this BigInteger and BigInteger val). |

min() | It is used to get the least value from both the compared object (this BigInteger and BigInteger val). |

mod() | It is used to calculate the mod by using (this BigInteger % BigInteger val). |

modInverse() | It is used to calculate the mod inverse by using the inverse of (this BigInteger) mod the given BigInteger (val). |

modPow() | It is used to calculate the mod pow by using the (this BigInteger) raised to the power of the first given argument (exp) mod the second given parameter [i.e. (this BigInteger) pow (exp) mod (BigDecimal val) ]. |

multiply() | It is used to represent the value of this BigInteger multiplied by the given argument. |

negate() | It is used to negate the value of this BigInteger. |

nextProbablePrime() | It is used to get the next probable prime number that should be higher than this BigInteger and there is a limit of composite number that should not be exceed 2 pow(-100). |

not() | It is used to perform not operation on the value of this BigInteger. |

or() | It is used to perform OR operation between the value of this BigInteger and the value of the given BigInteger. |

pow() | It is used to calculate the pow by using the value of (this BigInteger) is raised to the power of the value of the given parameter (val) [i.e. (this BigInteger) pow (val) ]. |

probablePrime() | It is used to get the BigInteger that holds the positive probable prime value with the given length. |

remainder() | It is used to calculate the remainder by using this BigInteger value is to be divided by the given BigInteger value. |

setBit() | It is used to set the bit value "1" at the given position in this BigInteger. |

shiftLeft() | It is used to shift the given number of bits towards left side in this BigInteger. |

shiftRight() | It is used to shift the given number of bits to the right in this BigInteger. |

signum() | It is used to perform signum (sign number) function on this BigInteger. |

subtract() | It is used to subtract the given value from the value of this BigInteger. |

testBit() | It is used to check whether the testing bit indexed at the given position is set or not in this BigInteger. |

toByteArray() | It is used to convert this BigInteger to a byte [] that holds 2's complement denotation of this BigInteger and the array capacity is enough to represent this BigInteger with one extra bit for sign. |

toString() | It is used to represent decimal string of this BigInteger. |

valueOf() | It is used to represent the given long value into a BigInteger. |

xor() | It is used to perform xor operation between this BigInteger. |

TOP Interview Coding Problems/Challenges

- Run-length encoding (find/print frequency of letters in a string)
- Sort an array of 0's, 1's and 2's in linear time complexity
- Checking Anagrams (check whether two string is anagrams or not)
- Relative sorting algorithm
- Finding subarray with given sum
- Find the level in a binary tree with given sum K
- Check whether a Binary Tree is BST (Binary Search Tree) or not
- 1[0]1 Pattern Count
- Capitalize first and last letter of each word in a line
- Print vertical sum of a binary tree
- Print Boundary Sum of a Binary Tree
- Reverse a single linked list
- Greedy Strategy to solve major algorithm problems
- Job sequencing problem
- Root to leaf Path Sum
- Exit Point in a Matrix
- Find length of loop in a linked list
- Toppers of Class
- Print All Nodes that don't have Sibling
- Transform to Sum Tree
- Shortest Source to Destination Path

Comments and Discussions