How do I convert from int to Long in Java?
To convert an int
to a long
in Java, you can simply use the typecast operator (long)
and place it in front of the value you want to convert. For example:
int x = 12345;
long y = (long) x;
This will assign the value of x
to y
as a long
.
Alternatively, you can use the Long.valueOf()
method to convert an int
to a long
. For example:
int x = 12345;
long y = Long.valueOf(x);
This will also assign the value of x
to y
as a long
.