- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to create an empty array in Kotlin?
An array is a collection where we can store multiple items of the same type. We can consider an array of integers or an array of strings. This is very useful, for example, whenever we need to store the name of 1000 students in a single variable.
Example – Using arrayOf()
In this example, we will see how we can create an empty array in Kotlin. We will be creating an empty array of Strings and manipulate the same in the program.
fun main(args: Array<String>) { // Declareting empty array of type String val emptyStringArray = arrayOf<String>() println("Example of empty String array") // printing the empty array println(emptyStringArray.contentToString()) // Declareting empty array of type Int val emptyIntArray = arrayOf<Int>() println("Example of empty Int array") // printing the empty array println(emptyIntArray.contentToString()) }
Output
On execution, it will produce the following output −
Example of empty String array [] Example of empty Int array []
- Related Articles
- How to initialize an empty array list in Kotlin?
- C# program to create an empty string array
- In Javascript how to empty an array
- How to empty an array in Java
- How to empty an array in JavaScript?
- How to create an empty list in Python?
- How to create an empty dictionary in Python?
- How to create an empty tuple in Python?
- How to create an empty VIEW in MySQL?
- How to create an empty matrix in R?
- How to create an empty class in Python?
- How to create an empty data frame in R?
- How to create an array in Kotlin like in Java by just providing a size?
- How to create an empty file using Python?
- How to declare an empty string array in C#?

Advertisements