Type casting is a way of converting data from one data type to another data type. This process of data conversion is also known as type conversion or type coercion.
In Java, we can cast both reference and primitive data types. By using casting, data can not be changed but only the data type is changed.
Note: type casting is not possible for a Boolean
data type.
There are 13 types of conversion in Java. In this article, we will only look at 2 major types:
To read about the other types of casting, refer to this documentation.
string
is not compatible with a boolean data type.