java arraylist contains(object) code example

Example: ArrayList contains(Object o) method in java

import java.util.ArrayList;
public class ArrayListContainsMethodExample
{
   public static void main(String[] args)
   {
      ArrayList<String> names = new ArrayList<String>(5);
      names.add("virat");
      names.add("dhoni");
      names.add("rohit");
      names.add("vijay");
      names.add("ajay");
      System.out.println("Names: " + names);
      System.out.print("Does list contains name dhoni?: ");
      System.out.println(names.contains("dhoni"));
      System.out.print("Does list contains name Sudhakar?: ");
      System.out.println(names.contains("Sudhakar"));
   }
}

Tags:

Java Example