The set() method takes 2 parameters: the index of the element and the value to be inserted. The get() method takes a single parameter-the index of the element and returns the value of the item at that index. ![]() The get() and set() functions are said to be member functions. Therefore, we can access the data of a class object via its member functions. The first element is first, subsequent elements are the previous element plus a step. Progressions have three essential properties: the first element, the last element, and a non-zero step. Now, let’s see how to access and modify them.Īs you know, an array in Kotlin is basically a class. In Kotlin, these progressions are defined by special types: IntProgression, LongProgression, and CharProgression. So far, we have seen how to create and initialize an array in Kotlin. ![]() Other factory methods available for creating arrays: ![]() These classes do not extend the Array class however, they implement the same methods and properties.įor example, the factory method to create an integer array is:
0 Comments
Leave a Reply. |