Kotlin Type casting and conversionType casting is a process of converting one data type to another type, for example – converting int to long, long to double etc. In this tutorial we will learn how to do type conversion in Kotlin. In Kotlin the conversion is not automatic, we need to explicitly do the type conversion. Type cast objects using the
isoperator or its negated form
!isto perform a runtime check that identifies whether an object conforms to a given type.
Kotlin Int to String using toString() function
.toString()returns a string representation of the object. It is not just restricted to converting Int to String. You can use it to convert other data type like Boolean to String.
Kotlin Int to Long using toLong() functionWe use the
toLong()function to convert int to long in Kotlin.
In this page (written and validated by A. Gawali) you learned about Kotlin Type casting and conversion . What's Next? If you are interested in completing Kotlin tutorial, your next topic will be learning about: Kotlin String concatenation.
Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue: firstname.lastname@example.org.