Java Program to Convert int to long - The Coding Shala

Home >> Java Programs >> Convert int to long

 Hey there, welcome back to another post. In this post, we are going to learn how to convert int to long in Java.

Java Program to Convert int to long

We can convert int to long using the below ways:

  • When we convert from smaller data type to larger data type, the Java compiler does it automatically, knowns as implicit conversion.
  • Using Long Wrapper class's valueOf() method.
Java Program: 


public class Main {

    public static void main(String[] args) {
        int intNumber = 15;

        // Implicit type casting for smaller to larger data types
        long longNumber1 = intNumber;
        System.out.println("Implicit Converted long number is: " + longNumber1);

        // using Long wrapper class
        long longNumber2 = Long.valueOf(intNumber);
        System.out.println("Using Wrapper class converted long number is: " + longNumber2);


Implicit Converted long number is: 15
Using Wrapper class converted long number is: 15

Other Posts You May Like
Please leave a comment below if you like this post or found some errors, it will help me to improve my content.


Popular Posts from this Blog

Shell Script to find sum, product and average of given numbers - The Coding Shala

Shell Script to Display the digits which are at odd positions in a given 5-digit number - The Coding Shala

Richest Customer Wealth LeetCode Solution - The Coding Shala

Add two numbers in Scala - The Coding Shala

LeetCode - Shuffle the Array Solution - The Coding Shala