Java – How to Convert Integer to Long
In this section, we will show you how to convert Integer to Long in Java.In Java, we can use Long.valueOf() to convert an Integer to a Long.
Integer i = 7; //example
Long l = Long.valueOf(i.longValue());
This avoids the performance hit of converting to a String. The longValue() method in Integer is just a cast of the int value. The Long.valueOf() method gives the vm a chance to use a cached value.
Main.java
public class Main {
public static void main(String[] args) {
Integer i = 7;
Long l = Long.valueOf(i.longValue());
System.out.println(l);
}
}
Console Output:
7
More topics,