Simply:

Integer i = 7;
Long l = new Long(i);
Answer from vahid kh on Stack Overflow
๐ŸŒ
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....
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
๐ŸŒ
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
๐ŸŒ
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.
๐ŸŒ
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 ...
๐ŸŒ
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 ...
๐ŸŒ
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); } }
๐ŸŒ
Vultr Docs
docs.vultr.com โ€บ java โ€บ examples โ€บ convert-int-type-variables-to-long
Java Program to convert int type variables to long | Vultr Docs
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 ...
๐ŸŒ
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 } }
๐ŸŒ
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.
๐ŸŒ
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 ...
๐ŸŒ
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!