char to long Java

char to long Java


After knowing primitive data types and Java rules of Data Type Casting (Type Conversion), let us cast char to long.

The long takes 8 bytes of memory and char takes 2 bytes of memory. 2 bytes memory value can be assigned to 8 bytes value and is done implicitly by JVM. But the reverse operation, long to char requires explicit casting.

See the data types order to know the brief rules of casting.

byte –> short –> int –> long –> float –> double

The left-side value can be assigned to any right-side value and is done implicitly. The reverse like int to short requires explicit casting.

Following program on char to long does the implicit operation where a char is assigned to long. Observe the syntax of implicit casting.


char to long
Output screenshot of char to long Java

long l1 = ch;

The char ch is implicitly type casted to long l1. This is known as automatic promotion or widening conversion.

View all for 65 types of Conversions

Leave a Reply

Your email address will not be published. Required fields are marked *