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

Convert long data type to int type in java

高洛峰
Release: 2017-01-22 10:16:47
Original
2574 people have browsed it

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;
Copy after login

2. Call the intValue() method

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

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));
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template