Saturday, 12 April 2014

contains : Search for specific Element

boolean contains(Object o)
Returns true if this deque contains the specified element.
import java.util.*;
import java.util.concurrent.LinkedBlockingDeque;

class DequeContains{
  public static void main(String args[]){
    Deque<Integer> myDeque = new LinkedBlockingDeque<Integer> (5);
  
  myDeque.add(10);
  myDeque.add(20);
  myDeque.add(30);
  myDeque.add(40);
  myDeque.add(10);
  
  System.out.println("Elements in the Deque are "+ myDeque);

  System.out.println("\nIs Deque Contains 10 " + myDeque.contains(10));
  System.out.println("Is Deque Contains 90 " + myDeque.contains(90));

 }
}

Output
Elements in the Deque are [10, 20, 30, 40, 10]

Is Deque Contains 10 true
Is Deque Contains 90 false

1. throws ClassCastException if the type of the specified element is incompatible with this deque

2. throws NullPointerException if the specified element is null and this
deque does not permit null elements

Prevoius                                                 Next                                                 Home

No comments:

Post a Comment