Home  >  Article  >  Java  >  Convert long data type to int type in java

Convert long data type to int type in java

高洛峰
高洛峰Original
2017-01-22 10:16:472529browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn