- 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 empty an array in Java
Use List.clear() method to empty an array.
Example
import java.util.ArrayList; import java.util.List; public class Tester { public static void main(String[] args) { List<String> list = new ArrayList<>(); list.add("A"); list.add("B"); list.add("C"); list.add("D"); list.add("E"); list.add("F"); list.add("G"); list.add("H"); System.out.println("Original List " + list); list.clear(); System.out.println("Cleared List " + list); } }
Output
Original List [A, B, C, D, E, F, G, H] Cleared List []
- Related Articles
- In Javascript how to empty an array
- How to empty an array in JavaScript?
- How to Check if an Array is Empty or Not in Java
- How to create an empty array in Kotlin?
- How to write an empty function in Java
- How to declare an empty string array in C#?
- How to initialize an empty array list in Kotlin?
- How do I empty an array in JavaScript?
- How do you empty an array in C#?
- Java Program to Empty an ArrayList in Java
- How to check whether an array is empty using PHP?
- No. of ways to empty an array in JavaScript
- How to validate if JTable has an empty cell in Java?
- How to assign values to an array with null/empty objects in JavaScript?
- How do you create an empty list in Java?

Advertisements