An example of a list is a telephone number: it's a group of digits, their order is important, and they can repeat. Elements can occur more than once in a list. List is an ordered collection with access to elements by indices – integer numbers that reflect their position. The following collection types are relevant for Kotlin: For example, all the students in a department form a collection that can be used to calculate their average age. Objects in a collection are called elements or items. We only need to override the methods that require case-insensitive handling or modification.The Kotlin Standard Library provides a comprehensive set of tools for managing collections – groups of a variable number of items (possibly zero) that are significant to the problem being solved and are commonly operated on.Ĭollections are a common concept for most programming languages, so if you're familiar with, for example, Java or Python collections, you can skip this introduction and proceed to the detailed sections.Ī collection usually contains a number of objects (this number may also be zero) of the same type. Override fun containsAll(elements: Collection) = InnerList.lastIndexOf(element.toLowerCase()) ![]() Override fun lastIndexOf(element: String) = Override fun set(index: Int, element: String) = ![]() Override fun add(index: Int, element: String) ) Override fun add(element: String) = innerList.add(element.toLowerCase()) Private val innerList: MutableList = mutableListOf() Then you should update your code to use this class instead of the List you use currently: class CaseInsensitiveList( As you noticed, your current approach is error prone and I'd bet you stepped on that already a few times :) To solve that you can create custom container that will deal this this for you automatically, so you will no longer need to normalize your data prior inserting (or anything else).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |