
- Kotlin - Home
- Kotlin - Overview
- Kotlin - Environment Setup
- Kotlin - Architecture
- Kotlin - Basic Syntax
- Kotlin - Comments
- Kotlin - Keywords
- Kotlin - Variables
- Kotlin - Data Types
- Kotlin - Operators
- Kotlin - Booleans
- Kotlin - Strings
- Kotlin - Arrays
- Kotlin - Ranges
- Kotlin - Functions
- Kotlin Control Flow
- Kotlin - Control Flow
- Kotlin - if...Else Expression
- Kotlin - When Expression
- Kotlin - For Loop
- Kotlin - While Loop
- Kotlin - Break and Continue
- Kotlin Collections
- Kotlin - Collections
- Kotlin - Lists
- Kotlin - Sets
- Kotlin - Maps
- Kotlin Objects and Classes
- Kotlin - Class and Objects
- Kotlin - Constructors
- Kotlin - Inheritance
- Kotlin - Abstract Classes
- Kotlin - Interface
- Kotlin - Visibility Control
- Kotlin - Extension
- Kotlin - Data Classes
- Kotlin - Sealed Class
- Kotlin - Generics
- Kotlin - Delegation
- Kotlin - Destructuring Declarations
- Kotlin - Exception Handling
Kotlin Array - none() Function
The Kotlin array none() function checks whether the array or collection contains a specified element. It returns true if no elements match the given predicate, and false if any element matches the predicate.
Syntax
Following is the syntax of Kotlin array none() function −
fun <T> Array<out T>.none( predicate: (T) -> Boolean ): Boolean
Parameters
This function accepts predicate as a parameter.
Return value
This function returns a boolean value.
Example 1
The following is a basic example to demonstrate the use none() function −
fun main(args: Array<String>) { var array = arrayOf<Int>(1, 2, 3, 4) val elem = array.none({ it%5 == 0 }) println("$elem") }
Output
Following is the output −
true
Example 2
Now, let's create another example. Here, we have an array that match the specified predicate −
fun main(args: Array<String>) { var array = arrayOf<Int>(1, 2, 3, 4) val elem = array.none({ it%2 == 0 }) println("$elem") }
Output
The above code returns false if the predicate matched with any element −
false
Example 3
The below example uses the none function to return boolean value, If true if statement will run, Otherwise; else statement −
fun main(args: Array<String>) { var array = arrayOf<String>("Hello", "tutorialspoint", "India", "Pvt", "ltd") val length = array.none({it.length>5}); if(!length){ println("Array contains elements have length more than 5 ") } else{ println("Array doesn't contains elements have length more than 5 ") } }
Output
Following is the output −
Array contains elements have length more than 5