Q:

Java Convert int to long

belongs to collection: Java Conversion Programs

0

We can convert int to long in java using assignment operator. There is nothing to do extra because lower type can be converted to higher type implicitly.

It is also known as implicit type casting or type promotion.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Java int to long Example

Let's see the simple code to convert int to long in java.

public class IntToLongExample1{  
public static void main(String args[]){  
int i=200;  
long l=i;  
System.out.println(l);  
}}  

 

Output:

200

 

Java int to Long Example

We can convert int value to Long object by instantiating Long class or calling Long.valueOf() method.

Let's see the simple code to convert int to Long in java.

public class IntToLongExample2{  
public static void main(String args[]){  
int i=100;  
Long l= new Long(i);//first way  
Long l2=Long.valueOf(i);//second way  
System.out.println(l);  
System.out.println(l2);  
}}  

 

Output:

100
100

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Java Convert long to int... >>
<< Java Convert Object to String...