Kotlin - Basic Types
Numbers
| Type | Size |
| Double | 64 |
| Float | 32 |
| Long | 64 |
| Int | 32 |
| Short | 16 |
| Byte | 8 |
Characters
Kotlin represents character using
char.
Character should be declared in a single quote like ‘c’.
Please enter the following code in our coding ground and see how
Kotlin interpret s the character variable. Character variable cannot
be declared like number variables. Kotlin variable can be declared in
two ways - one using “var”
and another using “val”.
Boolean
Boolean is very simple like other
programming languages. We have only two values for Boolean –
either true or false. In the following example, we will see how
Kotlin interprets Boolean.
Strings
Strings are character arrays. Like
Java, they are immutable in nature. We have two kinds of string
available in Kotlin - one is called raw
String and another is
called escaped
String.
In the following example, we will make use of these strings.
Arrays
Arrays are a collection of
homogeneous data. Like Java, Kotlin supports arrays of different data
types. In the following example, we will make use of different
arrays.
Collections
Collection is a very important part
of the data structure, which makes the software development easy for
engineers. Kotlin has two types of collection - one is immutable
collection (which
means lists, maps and sets that cannot be editable) and another is
mutable collection (this
type of collection is editable). It is very important to keep in
mind the type of
collection used in your application, as Kotlin system does not
represent any specific difference in them.
In collection, Kotlin provides some
useful methods such as first(),
last(),
filter(),
etc. All these methods are self-descriptive and easy to implement .
Moreover, Kotlin follows the same structure such as Java while
implementing collection. You are free to implement any collection of
your choice such as Map and Set.
Ranges
Ranges is another unique
characteristic of Kotlin. Like Haskell, it provides an operator that
helps you iterate through a range. Internally, it is implemented
using rangeTo()
and its operator form is (..).
In
the following example, we will see how Kotlin interprets this range
operator.
Comments
Post a Comment