Convert long type to int type in java

Converting from int type to long type is an up-conversion and can be directly implicitly converted, but converting from long type to int type is down-conversion, and data overflow may occur: The
following conversion methods are mainly for reference:

One, forced type conversion
[java]

long ll = 300000;  
int ii = (int)ll;  

Two, call the intValue() method
[java]

long ll = 300000;  
int ii= new Long(ll).intValue();  

Three, first convert the long into a string String, and then into an Integer
[java]

long ll = 300000;  
int ii = Integer.parseInt(String.valueOf(ll)); 

Guess you like

Origin blog.csdn.net/qq_41353397/article/details/113447578