Posts

Showing posts with the label Integer to Long

Java – How to Convert Integer to Long

In this section, we will show you h ow to c onvert 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, Moshi - Convert JSON Array String to List and List to JSON Array String Moshi - How to convert Java object to JSON and JSON to Java object Genson - Convert JSON Array String to List and List to JSON Array String Genson - How to convert Java object to JSON and JSON to Java object Convert JSON Array String to List and List to JSON Array String with Jackson Con...