Simply:

Integer i = 7;
Long l = new Long(i);
Answer from vahid kh on Stack Overflow
People also ask

What are the main methods to convert an Integer to a Long in Java?
A: The main methods are using Long.valueOf(), longValue() method, Long.parseLong(), autoboxing, and explicit casting.
🌐
code2care.org
code2care.org › home › java › ways to convert integer or int to long in java
Ways to Convert Integer or int to Long in Java | Code2care
What is autoboxing in the context of Integer to Long conversion?
A: Autoboxing is a Java feature that automatically converts primitive types to their corresponding wrapper classes. For Integer to Long conversion, it involves casting the int to long, then autoboxing to Long.
🌐
code2care.org
code2care.org › home › java › ways to convert integer or int to long in java
Ways to Convert Integer or int to Long in Java | Code2care
Which method is the most efficient for Integer to Long conversion?
A: For most cases, Long.valueOf() is efficient due to its caching mechanism. However, for high-performance scenarios, direct casting (long) with autoboxing might be slightly faster.
🌐
code2care.org
code2care.org › home › java › ways to convert integer or int to long in java
Ways to Convert Integer or int to Long in Java | Code2care
🌐
W3Docs
w3docs.com › java
Converting Integer to Long
This allows you to use the same ... objects: Number n = new Integer(123); Long l = n.longValue(); ... You can also use the longValueExact() method of the Integer class to convert an Integer object to a Long object....
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-program-to-convert-int-to-long
Java Program to Convert int to long - GeeksforGeeks
July 23, 2025 - Since integer is a smaller data type compared to long, the compiler automatically converts int to long, this is known as Implicit type casting or type promotion. ... // Java program to demonstrate // use of implicit type casting import java.io.*; ...
🌐
Baeldung
baeldung.com › home › java › java numbers › convert int to long in java
Convert int to Long in Java | Baeldung
May 14, 2024 - In contrast, Long is a 64-bit two’s complement integer, which can hold values from -2^63 to 2^63-1. We usually use Long when the range provided by int isn’t sufficient. Java introduced a feature called autoboxing in its 5th version, which allows automatic conversion between primitive types and their corresponding wrapper classes. Let’s use autoboxing to convert an int to a Long directly:
🌐
Coderanch
coderanch.com › t › 395715 › java › converting-int-long
converting int to long (Beginning Java forum at Coderanch)
To convert long to int :- total =total+Integer.parseInt(String.valueOf(text)); To convert int to long :- text =text+Long.parseLong(String.valueOf(total)); regards, lalit [ February 26, 2004: Message edited by: Lalit K Kumar ] This seems like a very convoluted way to convert from one numeric ...
🌐
Mkyong
mkyong.com › home › java › java – convert integer to long
Java - Convert Integer to Long - Mkyong.com
August 1, 2019 - package com.mkyong.example; public class TestInteger { public static void main(String[] args) { Integer num = 1; System.out.println(num); // 1 Long numInLong = Long.valueOf(num); System.out.println(numInLong); // 1 } } ... Founder of Mkyong.com, ...
Find elsewhere
🌐
BeginnersBook
beginnersbook.com › 2019 › 04 › java-int-to-long-conversion
Java Convert int to long with examples
In the following example, we are converting int to long using valueOf() method of Long Wrapper class. The valueOf() method accepts integer as an argument and returns a long value after the conversion. public class JavaExample{ public static void main(String args[]){ int inum = 99; Long lnum ...
🌐
Javatpoint
javatpoint.com › java-int-to-long
Java Convert int to long
Java Convert int to long example and examples of string to int, int to string, string to date, date to string, string to long, long to string, string to char, char to string, int to long, long to int etc.
🌐
Code2care
code2care.org › home › java › ways to convert integer or int to long in java
Ways to Convert Integer or int to Long in Java | Code2care
September 20, 2024 - Constructs a newly allocated Long object that represents the specified long argument. public static void main(String[] args) { Integer i = 1000; Long l = new Long(i); System.out.println(l); } ... Note: It is better to avoid using this constructor ...
🌐
Vultr Docs
docs.vultr.com › java › examples › convert-int-type-variables-to-long
Java Program to convert int type variables to long
November 26, 2024 - Recognize that Java supports automatic type conversion from int to long. Assign an int value directly to a long variable. ... int myInt = 10000; long myLong = myInt; System.out.println("The converted long value is: " + myLong); Explain Code ...
🌐
Tutorial Gateway
tutorialgateway.org › java-program-to-convert-int-to-long
Java Program to Convert Int to Long
January 22, 2025 - import java.util.Scanner; public class IntToLong { private static Scanner sc; public static void main(String[] args) { int i; sc= new Scanner(System.in); System.out.println("\n Please Enter any Integer Value : "); i = sc.nextInt(); long l1 = i; long l2 = new Long(i); long l3 = Long.valueOf(i); System.out.println("The first way to convert int to Long = " + l1); System.out.println("The second way to convert int to Long = " + l2); System.out.println("The third way to convert int to Long = " + l3); } }
🌐
Programiz
programiz.com › java-programming › examples › int-to-long-conversion
Java Program to convert int type variables to long
Become a certified Java programmer. Try Programiz PRO! ... class Main { public static void main(String[] args) { // create int variables int a = 25; int b = 34; // convert int into long // using typecasting long c = a; long d = b; System.out.println(c); // 25 System.out.println(d); // 34 } }
🌐
TheServerSide
theserverside.com › blog › Coffee-Talk-Java-News-Stories-and-Opinions › String-to-long-in-Java
String to long in Java
// Text to Long in Java with valueOf String text = "10"; // Java String to long with autoboxing long face = Integer.valueOf(text); long twoFace = face + face ; System.out.println( face ); // prints 10 System.out.println( twoFace ); // prints 20 · Every Java wrapper class has a deprecated constructor that takes a String as an argument and converts that String to the corresponding type. ... In Java 17, these methods still work, but they are marked for removal so you should avoid this approach.
🌐
Scaler
scaler.com › home › topics › convert int to long in java
Convert int to Long in Java - Scaler Topics
April 7, 2024 - We can also convert an int variable to a long variable using explicit typecasting. We have to put the data type we want and the other variable/expression in the parentheses like the given syntax below: ... It creates a long data type value var ...
🌐
SourceBae
sourcebae.com › home › how to convert int to long in java: a comprehensive guide
How to Convert int to long in Java: A Comprehensive Guide - SourceBae
August 21, 2025 - Generally, type casting and data type conversion in Java are efficient operations. However, excessive and unnecessary conversions can impact performance. It’s essential to convert data types only when required. Yes, you can convert a long back to an int using type casting. However, be aware that if the long value is outside the int range, data loss may occur. In some cases, you may consider using BigInteger for arbitrary-precision integers or handle data type conversions through custom logic.
🌐
LabEx
labex.io › tutorials › java-java-integer-longvalue-method-117718
Java Data Type Conversion | Integer to Long | LabEx
Integer integerObject = ... the following command to compile the Java file: ... This lab demonstrated how to use the longValue() method to convert an Integer object to its long equivalent....
🌐
Apps Developer Blog
appsdeveloperblog.com › home › java › java conversion › convert int to long in java
Convert Int to Long in Java - Apps Developer Blog
March 22, 2024 - Learn how to convert int to long in Java using casting, wrapper class, and parsing methods. Explore potential issues and limitations.
🌐
WsCube Tech
wscubetech.com › resources › java › programs › convert-int-to-long
Convert integer to long in Java (6 Programs)
October 18, 2025 - Learn how to convert int type variables to long in Java with simple examples. Explore implicit conversion, explicit casting, Long.valueOf and more. Read now!