9/11/2023 0 Comments Kotlin arraylist![]() Let's create a simple example of ArrayList class define with empty ArrayList of String and add elements later.The wildcard type argument ? extends E indicates that this method accepts a collection of objects of E or a subtype of E, not just E itself. Kotlin ArrayList Example 1- empty ArrayList It does nothing in this ArrayList implementation. It is used to returns a string representation of the object. It is used to return new array of type Array with the elements of this collection. It is used to replaces the element from the specified position from current list with the specified element. ![]() Its remove the range of elements starting from startIndex to endIndex in which endIndex is not includes. Open fun removeRange(startIndex: Int, endIndex: Int) It is used to remove the specific index element from the list. It is used to remove a single instance of the specific element from current collection, if it is available. It is used to return the last occurrence of given element from the list or it returns -1 if the given element is not present in the list. It is used to return the index of first occurrence of specified element in the list or return -1 if the specified element in not present in the list. It is used to return the element at specified index in the list. It is used to removes all elements from the collection. It is used to add all the elements of specified collection into the current list at the specified index. Open fun addAll(index: Int, elements: Collection): Boolean It is used to add all the elements in the specified collection to current collection. Open fun addAll(elements: Collection): Boolean It is used to insert an element at specific index. It is used to add the specific element into the collection. It is used to create an ArrayList filled from the elements of collection. It is used to create an ArrayList of specified capacity. ![]() ![]() Constructor of Kotlin ArrayList Constructor The elements of ArrayList class are accessed randomly as it works on index basis. ArrayList class is non synchronized and it may contains duplicate elements. Kotlin ArrayList class follows the sequence of insertion order. ArrayList class provides both read and write functionalities. Which means the size of ArrayList class can be increased or decreased according to requirement. Kotlin ArrayList class is used to create a dynamic array. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |