Friday, 30 May 2014

ArrayList : contains (Object o) : Search for an Element

public boolean contains(Object o)
Returns true if this list contains the specified element.

import java.util.*;

class ArrayListContains{
 public static void main(String args[]){
  ArrayList<String> myList = new ArrayList<String> ();
  
  /* Add Elements to the List */
  myList.add("Hi");
  myList.add("How are you");
  myList.add("abcd");
  myList.add("Vector");
  
  System.out.println("Elements in the list are ");
  System.out.println(myList);
  
  System.out.print("Is list contains the string abcd ");
  System.out.println(myList.contains("abcd"));
  System.out.print("Is list contains the string wxyz ");
  System.out.println(myList.contains("wxyz"));
 }
}


Output
Elements in the list are
[Hi, How are you, abcd, Vector]
Is list contains the string abcd true
Is list contains the string wxyz false

Prevoius                                                 Next                                                 Home

No comments:

Post a Comment