3:06 pm - Monday September 26, 2901

Check whether an object is present in ArrayList boolean Contains(Object o)

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 specified element is present in the list or not. It returns boolean result(i.e true or false) based on the specified element.

Example Program

import java.util.ArrayList;

    public class Contains 
{

    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");

       System.out.println(al);

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

       boolean b=al.contains("Casting");

       if(b==true)

       {

           System.out.println("The concept is present in java and it is true");

       }

           else

           {

               System.out.println("The concept is not present in java and it is false");

            }
   }

}

Output

   Concepts in java:

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

   Contains function:

   The concept is present in java and it is true

 

 

BACK

Filed in: Java Examples

Comments are closed.