
- 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 - isEmpty() Function
The Kotlin array isEmpty() function is used to check whether the array is empty. It returns true if an array is empty, otherwise, it returns false.
Syntax
Following is the syntax of Kotlin array isEmpty() function −
fun <T> Array<out T>.isEmpty(): Boolean
Parameters
This function does not accepts any parameters.
Return value
This function returns boolean value. true if an array is empty. Otherwise; false.
Example 1
Following is the basic example to demonstrate the use of isEmpty() function −
fun main(args: Array<String>) { val array = arrayOf<Int>() // check array is empty or not val empty = array.isEmpty() println("$empty") }
Output
Following is the output −
true
Example 2
Now, let's see another example. Here, we created an array stores the strings. We then use isEmpty function to check array is empty or not −
fun main(args: Array<String>) { val array = arrayOf<String>("tutorialspoint", "India") // check array is empty or not val empty = array.isEmpty() if(empty == true){ print("Array is empty!") }else{ print("Array is not empty!") } }
Output
After execution of the above code we get the following output −
Array is not empty!
kotlin_arrays.htm
Advertisements