BigInteger valueOf() Method in Java Last Updated : 29 Nov, 2019 Suggest changes Share 3 Likes Like Report The java.math.BigInteger.valueOf(long value) method returns a BigInteger whose value is equal to value of long passed as parameter. This method is static method so It is not necessary to create object of BigInteger class to use this method.we can call this function by BigInteger.valueOf(long value) code. Syntax: public static BigInteger valueOf(long val) Parameter: This method accepts a single parameter value which is the value of the BigInteger to be created. Return Value: This method returns the BigInteger whose value is equal to value of long passed as parameter. Below programs illustrate valueOf(long value ) method of BigInteger class: Example 1: To apply valueOf() without creating BigInteger Object. Java // Java program to demonstrate valueOf() method of BigInteger import java.math.BigInteger; public class GFG { public static void main(String[] args) { // Creating 2 BigInteger objects BigInteger b1, b2; // apply valueOf() b1 = BigInteger.valueOf(456782765); b2 = BigInteger.valueOf(12345543); // print result System.out.println("Value of BigInteger b1: " + b1); System.out.println("Value of BigInteger b2: " + b2); } } Output: Value of BigInteger b1: 456782765 Value of BigInteger b2: 12345543 Example 2: Apply valueOf() by creating BigInteger object. Java // Java program to demonstrate valueOf() method of BigInteger import java.math.BigInteger; public class GFG { public static void main(String[] args) { // Creating BigInteger objects BigInteger b1, b2, b3; // create bigInteger with some value b1 = new BigInteger("532721"); // apply valueOf() b2 = b1.valueOf(234567898); b3 = b2.valueOf(98765432); // print result System.out.println("Value of BigInteger 1: " + b2); System.out.println("Value of BigInteger 2: " + b3); } } Output: Value of BigInteger 1: 234567898 Value of BigInteger 2: 98765432 Reference: https://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html#valueOf(long) A AmanSingh2210 Follow 3 Article Tags : Java java-basics Java-Functions java-math Java-BigInteger Java-math-package +2 More Explore Java BasicsIntroduction to Java3 min readJava Programming Basics9 min readJava Methods6 min readAccess Modifiers in Java4 min readArrays in Java7 min readJava Strings8 min readRegular Expressions in Java3 min readOOP & InterfacesClasses and Objects in Java9 min readAccess Modifiers in Java4 min readJava Constructors4 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages7 min readJava Interface7 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java4 min readIterator in Java5 min readJava Comparator Interface6 min readException HandlingJava Exception Handling6 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial3 min readSynchronization in Java10 min readFile Handling in Java4 min readJava Method References9 min readJava 8 Stream Tutorial7 min readJava Networking6 min readJDBC Tutorial5 min readJava Memory Management4 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers15+ min readJava Programs - Java Programming Examples7 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions5 min readJava Quiz1 min readJava Project Ideas For Beginners and Advanced15+ min read My Profile ${profileImgHtml} My Profile Edit Profile My Courses Join Community Transactions Logout Like