![]() ![]() The method below demonstrates how to use the firstOrNull() method. If no element matches the given predicate function, then null is returned. This method returns the first element from the list that satisfies the provided the predicate. This method takes a predicate function as an argument. Syntax to get the first element that matches the predicate fun List.firstOrNull( Returns the first element if the ArrayList is not empty. ![]() Syntax to get the first element // to get first element Declaring Any as return type basically means: any Kotlin type can be returned. If no element matches the provided predicate function, then null is returned. Any is the root of the Kotlin class hierarchy. To get the first element of the ArrayList that satisfies the provided predicate function Predicate is a Functional interface, which takes one argument and returns either true or false based on the condition defined.If the ArrayList is empty, then null is returned. To get the first element of the ArrayList.The firstOrNull() method can be used in two ways.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |