Notification

No New notification

Learn to code with PrepInsta

Check PrepInsta Coding Blogs, Core CS, DSA etc

One Subscription, For Everyone

Get 200+ Courses under one Subscription

  • aptitude
  • aws_cloud
  • competitive-coding
  • dbms
  • logical_reasoning
  • operating-system
  • verbal
  • tcs_nqt
  • data_science
  • ethical_hacking
  • dsa
  • verbal
  • basic_coding
  • python
  • cpp
  • java
  • basic_coding
  • python
Explore PrepInsta Prime

Never Miss an OffCampus Update

Get OffCampus Updates on Social Media from PrepInsta

Java ArrayList isEmpty() Method

ArrayList-isEmpty

What is ArrayList?

ArrayList provides us with dynamic arrays. The ArrayLists are resizable in nature , we can add or remove an element at anytime. It is not compulsory to mention size while declaring it. The ArrayList  is a part of Java framework and can be found in the java.util pacakge. ArrayList have many inbuilt methods which we can use. One of them is Java ArrayList isEmpty() Method.

Here on this page we will discuss about ArrayList isEmpty() method.

Java ArrayList isEmpty() Method

The isEmpty() method can be found in java.util.ArrayList package. This method is used to check if list is empty or not . It returns true if the ArrayList is empty else it returns false. It’s syntax , parameters, output are discussed below with examples.

isEmpty() Syntax :

ArrayList.isEmpty() 

isEmpty() Parameters :

this method does not take any parameters 

isEmpty() return value

True: When ArrayList is empty. False: When ArrayList contains any element.
Java-ArrayList-isEmpty-Method

ArrayList isEmpty() Method Examples:

Example 1 :

Run
 import java.util.ArrayList; class Main { public static void main(String[] args) { // creating an String ArrayList ArrayList list = new ArrayList<>(); // insert element to the arraylist list.add("Prep"); list.add("Insta"); list.add("Prime"); // check if list is empty or not boolean result = list.isEmpty(); System.out.println("list is empty: "+ result); } }

Output

list is empty: false 

Example 2 :

Run
import java.util.ArrayList; class Main { public static void main(String[] args) { // creating an String ArrayList ArrayList list = new ArrayList<>(); // remove the element Prime from the list boolean result = list.isEmpty(); System.out.println("list is empty: "+ result); } }

Output

list is empty: true 

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription