10:45 am - Thursday January 19, 2017

Check whether a given ArrayList is Empty boolean isEmpty()

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

BACK

                             This method is used to check whether the given list is empty or not. If the list contains no element then the boolean result is true or else it returns false.

 Example Program

import java.util.ArrayList;

public class BoolEmpty 
{
  public static void main(String[] args)

   {

       ArrayList<String> al=new ArrayList<String>();

       System.out.println("Concepts in java:");

       al.add("Constructor");

       al.add("Inheritance");

       al.add("Polymorphism");

       al.add("Exceptional Handling");

       al.add("Casting");

       al.add("Packages");

       System.out.println(al);

       System.out.println("Empty function:");

      if(al.isEmpty())

        {

          System.out.println("Boolean result is True");

        }

      else

        {

          System.out.println("Boolean result is False because list contains value");

        }
 
   }

}

Output

   Concepts in java:

   [Constructor, Inheritance, Polymorphism, Exceptional Handling, Casting, Packages]

   Empty function

   Boolean result is False

BACK

Filed in: Java Examples

Comments are closed.