Kotlin Data TypeData type (basic type) refers to type and size of data associated with variables and functions. Data type is used for declaration of memory location of variable which determines the features of data. In Kotlin, everything is an object, which means we can call member function and properties on any variable. Kotlin built in data type are categorized as following different categories:
Number TypesNumber types of data are those which hold only number type data variables. It is further categorized into different Integer and Floating point.
Character (Char) Data TypeCharacters are represented using the keyword Char. Char types are declared using single quotes ('').
Example Boolean Data TypesBoolean data is represented using the type Boolean. It contains values either true or false.
Example ArrayArrays in Kotlin are represented by the Array class. Arrays are created using library function arrayOf() and Array() constructor. Array has get (), set() function, size property as well as some other useful member functions. Creating Array using library function arrayOf()The arrayOf() function creates array of wrapper types. The item value are passed inside arrayOf() function like arrayOf(1,2,3) which creates an array[1,2,3]. The elements of array are accessed through their index values (array[index]). Array index are start from zero. Creating Array using Array() constructorCreating array using Array() constructor takes two arguments in Array() constructor:
StringString in Kotlin is represented by String class. String is immutable, which means we cannot change the elements in String. String declaration: Types of StringString are categorize into two types. These are: 1. Escaped String: Escape String is declared within double quote (" ") and may contain escape characters like '\n', '\t', '\b' etc. 2. Raw String: Row String is declared within triple quote (""" """). It provides facility to declare String in new lines and contain multiple lines. Row String cannot contain any escape character. Next TopicKotlin Type Conversion |