How to Convert Int to Long in Java

In this tutorial, we will learn how to convert int numeric value to long value, int value to Long wrapper object and vice versa in Java easily. To convert int to long numeric value in Java, we use an assignment operator.

We do not need to do extra to convert int to long. This is because the lower type can be converted to higher type implicitly. We also known this conversion as implicit type casting or type promotion.

Let’s create a simple Java program to convert int to long easily.

Example 1:

// Java Program to demonstrate the conversion of int into long implicitly.
package javaConversion;
public class IntToLongConversion {
public static void main(String[] args) 
{
   int i = 9999; 
   long l = i;  
   System.out.println("Long numeric value after conversion: " +l);
 }
}
Output:
     Long numeric value after conversion: 9999

Converting Int to Long object in Java using Long.valueOf() method


We can convert int numeric value to Long object by creating an object of Long wrapper class and then call its valueOf() method.
[blocksy-content-block id=”12371″]
Let’s make a simple Java program for converting int to Long object using valueOf() method of Long class.

Example 2:

// Java Program to demonstrate the conversion of int into long object.
package javaConversion;
public class IntToLongConversion {
public static void main(String[] args) 
{
   int num = 9999; 
   Long l1 = new Long(num); // first way  
   Long l2 = Long.valueOf(num); // second way  
   System.out.println(l1);  
   System.out.println(l2); 
 }
}
Output:
      9999
      9999

In the above program, the valueOf() method of Long wrapper class returns a Long instance representing the specified long value.

Convert Long to Int in Java using typecasting


To convert long to int numeric value in Java, we use typecasting. To convert the higher data type to lower, we perform typecasting in the program through a typecast operator (datatype).
[blocksy-content-block id=”12121″]
Let’s make a Java program for converting long primitive type into int value using typecasting.

Example 3:

// Java Program to demonstrate the conversion of long into int value.
package javaConversion;
public class LongToIntConversion {
public static void main(String[] args) 
{
   long l = 600;  
   int i = (int)l;  
   System.out.println(i); 
 }
}
Output:
     600

Long object to int Conversion


For converting Long object to int value in Java, we use intValue() method of Long class. Let’s take a simple program for converting Long object to int in Java.

Example 4:

// Java Program to demonstrate the conversion of Long object into int value using intValue() method.
package javaConversion;
public class LongToIntConversion {
public static void main(String[] args) 
{  
   Long l = new Long(657);  
   int i = l.intValue();  
   System.out.println(i); 
 }
}
Output:
      657

In this example program, we have used intValue() method of Long class for converting Long object to int value. The intValue() method returns the value of this Long as an int after a narrowing primitive conversion.


In this tutorial, you learned how to convert a primitive type long value to int and vice versa in Java easily. Hope that you will have understood and practiced all programs based on the conversion of int to long in Java.
Thanks for reading!!!

DEEPAK GUPTA

DEEPAK GUPTA

Deepak Gupta is the Founder of Scientech Easy, a Full Stack Developer, and a passionate coding educator with 8+ years of professional experience in Java, Python, web development, and core computer science subjects. With strong expertise in full-stack development, he provides hands-on training in programming languages and in-demand technologies at the Scientech Easy Institute, Dhanbad.

He regularly publishes in-depth tutorials, practical coding examples, and high-quality learning resources for both beginners and working professionals. Every article is carefully researched, technically reviewed, and regularly updated to ensure accuracy, clarity, and real-world relevance, helping learners build job-ready skills with confidence.