0 votes
in Kotlin by
Explain Array in Kotlin

1 Answer

0 votes
by

An Array is the homogenous set of data types and is one of the most fundamental data types which is used to store the same types of data in the contiguous memory location. An Array is significant for the organization of data in any programming language so that multiple data stored ant a single place is easy to search or sort.

In Kotlin, arrays are a mutable collaboration of the same data types rather than being native data types.

Here are certain properties of an array in Kotlin

  • The size of the array cannot be changed once declared.
  • Arrays in Kotlin are mutable.
  • Arrays are stored in contiguous memory locations.
  • An array can be accessed with the help of indexes like a[1], a[2], et – cetera.
  • The index of an array starts with zero that is a[0].

In Kotlin, an array can be defined in two different methods

By Using arrayOf() Function :

In Kotlin, there is a major usage of library functions. One such library function is arrayOf() function, which is used to define an array by passing the values of the variables to the function.

For Example: Implicit type declaration of array using arrayOf() function

val x = arrayOf(1,2,3,4,5,6,7,8,9)

For Example: Explicitly type declaration of array using arrayOf() function.

Val y = arrayOf<Int>(1,2,3,4,5,6,7,8,9)

By Using Array Constructor :

In Kotlin, there is a class with the name of Array. Therefore, it is feasible to use an array of the constructor to create an array. The array in constructor holds two major parameters.

Related questions

0 votes
asked May 26, 2022 in Kotlin by Robin
0 votes
asked May 26, 2022 in Kotlin by Robin
0 votes
0 votes
0 votes
asked May 26, 2022 in Kotlin by Robin
...