Conversion from int type to long type is upward conversion, which can be directly implicitly converted, but conversion from long type to int type is downward conversion, and data overflow may occur:
Mainly as follows: A conversion method, for reference:
1. Forced type conversion
long ll = 300000; int ii = (int)ll;
2. Call the intValue() method
long ll = 300000; int ii= new Long(ll).intValue();
3. First convert the long into a string String, and then convert it into an Integer
long ll = 300000; int ii = Integer.parseInt(String.valueOf(ll));
These three methods are relatively simple and clear.
For more articles related to converting long data type to int type in java, please pay attention to PHP Chinese website!