Java Collections Framework- ArrayDeque class

Java Collections Framework- ArrayDeque class


Posted in : Java Posted on : December 1, 2010 at 5:00 PM Comments : [ 0 ]

java.util.ArrayDeque implements a double-ended queue, which allows efficient insertion and deletion at both ends.

Java Collections Framework- ArrayDeque class

java.util.ArrayDeque implements a double-ended queue, which allows efficient insertion and deletion at both ends. ArrayDeque is a resizable array implementation of the Deque interface. It has no capacity restrictions. It will perform faster than stack when used as stack and faster than linked list when used access by multiple threads. Null elements are prohibited. This class is a member of the Java Collections Framework. This class and its iterator implement all of the optional methods of the Collection and Iterator interfaces.

ArrayDeque has the constructors shown here:

ArrayDeque() - Constructs an empty array deque with an initial capacity sufficient to hold 16 elements.

ArrayDeque(Collection c) - Constructs a deque containing the elements of the specified collection, in the order they are returned by the collection's iterator.

ArrayDeque(int capacity) - Constructs an empty array deque with an initial capacity sufficient to hold the specified number of elements.

In addition to the methods defined by Collection, ArrayDeque defines some of its own, which are as follows-

  • addFront()
  • getFirst()
  • peekFirst()
  • descendingIterator()
  • isEmpty()
  • offer()
  • peek()
  • poll()
  • pop() 
  • remove()
  • removeFirstOccurrence() 

Here is an example that demonstrates a ArrayDeque.- ArrayDequeDemo.java

package devmanuals.com;

import java.util.*;

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

		ArrayDeque ADeque = new ArrayDeque();
		ADeque.add("A");
		ADeque.add("B");
		ADeque.add("C");
		ADeque.add("D");
		ADeque.add("E");
		System.out.println("The element of ArrayDeque :" + ADeque);

	}
}
Output:-
The element of ArrayDeque :[A, B, C, D, E]

Download This Code.
Here is the more example of methods of ArrayDeque class.
Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics