Google News
logo
Kotlin - Interview Questions
What are the various data types available in Kotlin?
Kotlin provides a rich set of data types that can be used to represent different kinds of values. Here are the various data types available in Kotlin:

1. Numbers :
   * `Byte`: 8-bit signed integer (-128 to 127).
   * `Short`: 16-bit signed integer (-32,768 to 32,767).
   * `Int`: 32-bit signed integer (-2,147,483,648 to 2,147,483,647).
   * `Long`: 64-bit signed integer (-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807).
   * `Float`: 32-bit floating-point number.
   * `Double`: 64-bit floating-point number.

2. Characters :
   * `Char`: Represents a single Unicode character.

3. Booleans :
   * `Boolean`: Represents either `true` or `false`.

4. Strings :
   * `String`: Represents a sequence of characters.

5. Arrays :
   * `Array`: Represents a fixed-size collection of elements of the same type.
   * Kotlin also provides specialized array types like `IntArray`, `CharArray`, etc., for arrays of specific primitive types.

6. Collections :
   * Kotlin standard library provides a rich set of collection types such as `List`, `Set`, and `Map` for working with collections of elements.

7. Ranges :
   * Kotlin allows the creation of ranges using the range operator (`..`) to represent a sequence of values between a start and end point.

8. Nullability :
   * Kotlin supports nullable types by allowing a data type to hold either a non-null value or a null value. Nullable types are denoted by appending `?` to the type declaration.

9. User-defined Types :
   * Kotlin allows the creation of custom data types using classes, interfaces, enums, and sealed classes.

Additionally, Kotlin provides type inference, which allows the compiler to automatically determine the data type based on the assigned value, reducing the need for explicit type declarations in many cases.
Advertisement