Java Program - Convert Int to Long - Tutorial Kart
[Pages:3]Java Program to Convert Int to Long
Java ? Convert Int to Long
In this tutorial, we shall learn how to convert an integer value to a long value.
Firstly, we shall go through the process of widening primitive conversion, where we shall take the advantage of implicit casting of lower datatype to higher datatypes. Secondly, we shall discuss about Integer.longValue() method, which returns this integer as a long.
Convert Int to Long ? Widening Casting
Int is a smaller datatype and long is a larger datatype. So, when you assign an int value to long variable, the conversion of int to long automatically happens in Java. This is also called widening casting or widening primitive conversion.
So, to convert an int to long using widening casting, you can just assign a value of int to long.
In the following example, we have a variable n which is of int type. We shall assign i to long variable l during its declaration.
Java Program
/** * Java Program - Convert Int to Long */ public class IntToLong {
public static void main(String[] args) { Integer i = 125; long l = 125; System.out.println(l);
} }
Output
125
Convert Int Bits to Long ? Integer.longValue()
Integer.longValue() performs a widening primitive conversion on this integer object and returns a long value.
In the following example, we shall take an integer object initialized to a value, and call longValue() method on this object.
Java Program
/** * Java Program - Convert Int to Long */ public class IntToLong {
public static void main(String[] args) { Integer i = 85; long l = i.longValue(); System.out.println(l);
} }
Output
Conclusion
In this Java Tutorial, we learned how to write Java programs to convert an Int to Long, with the help of example Java programs.
Java Tutorial Java - String to Int Java - String to Float Java - String to Double Java - String to Long Java - String to Boolean Java - Int to String Java - Int to Float Java - Int to Double
Java - Int to Double Java - Int to Long Java - Int to Char Java - Float to String Java - Float to Int Java - Float to Double Java - Float to Long Java - Long to String Java - Long to Float Java - Long to Double Java - Long to Int Java - Double to String Java - Double to Float Java - Double to Int Java - Double to Long Java - Char to Int Java - Boolean to String
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- java program convert int to char tutorial kart
- java printf method quick reference colorado state university
- if statements and booleans stanford university
- java quick reference ap students college board
- string operations university of wisconsin madison
- strings and chars stanford university
- final practice exam solution colorado state university
- destring — convert string variables to numeric variables and
- java program convert int to long tutorial kart
- java strings
Related searches
- matlab convert int to double
- excel convert int to string
- vba convert int to string
- convert int to string python 3
- convert int to str
- convert int to date python
- python convert int to char ascii
- convert int to binary java
- java program convert binary to decimal
- python convert int to binary
- convert int to binary python
- convert int to int array