6/1/2023 0 Comments Kotlin any![]() ![]() * true if any element in is found in the receiving collection.įun Collection. * elements the elements to look for in the receiving collection. * Returns true if the receiving collection contains any of the specified elements. They are very similar to those from the Java language, but the Kotlin language creators tried to make them a little bit more intuitive and understandable by introducing special keywords like out and in. Each key in a map is unique, and it can only be associated with one value. Maps can store a collection of zero or more key-value pairs. They’re also known as dictionaries or associative arrays in other programming languages. Here's an example implementation of an extension function defined on the Collection class, the details of which are inspired by other answers in this thread: /** Overview In this article, we’ll be looking at the generic types in the Kotlin language. Kotlin Map s Maps are a common data structure in computer science. The implementation detail is tucked away inside of that function and can be changed in a single place in future should you wish to change the implementation. All of the places where you need to check whether an Array or Collection contains any of the elements of another then remains nice and neat, as follows: arrayOf(1, 2, 3).containsAny(2, 3) ![]() For me, the best way to solve this is to define a containsAny(elements:) extension function on the Array and/or Collection class. ![]()
0 Comments
Leave a Reply. |