Java ArrayDeque Class

  • ArrayDeque is i of the collection framework fellow member which implements Deque, Cloneable as well as Serializable interfaces.
  • ArrayDeque provides Resizable-array implementation hence it has no capacity restrictions as well as it volition grow equally per requirement.
  • In the absence of external synchronization, they are non thread safe. So they produce non permit multiple threads to access it concurrently.
  • Also ArrayDequenot permit to shop zip elements.
  • ArrayDeque Class is faster than LinkedList when used equally a queue as well as faster than Stack when used equally a stack.
  • If ArrayDeque is modified subsequently the iterator creation as well as if it is non modified past times iterators ain method hence it volition throw ConcurrentModificationException. So inward concurrent modification, Iterator volition fail.
Java ArrayDeque Class hierarchy

Important methods of ArrayDeque Class
  • boolean add(E e) : It volition insert given chemical component inward ArrayDeque.
  • void addFirst(E e) : It volition add together given chemical component at the showtime of ArrayDeque.
  • void addLast(E e) : It volition add together given chemical component at the destination of ArrayDeque.
  • void clear() : It volition take all elements from ArrayDeque to clear it.
  • ArrayDeque<E> clone() : It volition render re-create of ArrayDeque.
  • boolean contains(Object o) : It volition render truthful if specified chemical component available inward ArrayDeque.
  • Iterator<E> descendingIterator() : It volition render iterator inward contrary sequential lodge over the elements of ArrayDeque.
  • E element() : It volition become head(first) chemical component from this ArrayDeque.
  • E getFirst() : It volition become head(first) chemical component from this ArrayDeque.
  • E getLast() : It volition become final chemical component from this ArrayDeque.
  • boolean isEmpty() : It volition render truthful if ArrayDeque is empty.
  • boolean offer(E e) : It volition insert specified chemical component at the destination of this ArrayDeque.
  • boolean offerFirst(E e) : It volition insert specified chemical component at the showtime of this ArrayDeque.
  • boolean offerLast(E e) : It volition insert specified chemical component at the destination of this ArrayDeque.
  • E peek() : It volition cry back as well as render caput chemical component from ArrayDeque. Return zip if ArrayDeque is empty.
  • E peekFirst() : It volition cry back as well as render head(first) chemical component from ArrayDeque. Return zip if ArrayDeque is empty.
  • E peekLast() : It volition cry back as well as render final chemical component from ArrayDeque. Return zip if ArrayDeque is empty.
  • E poll() : It volition take caput chemical component from ArrayDeque. Return zip if ArrayDeque is empty.
  • E pollFirst() : It volition take head(first) chemical component from ArrayDeque. Return zip if ArrayDeque is empty.
  • E pollLast() : It volition take final chemical component from ArrayDeque. Return zip if ArrayDeque is empty.
  • E pop() : It volition popular an chemical component from stack represented past times this ArrayDeque.
  • void push(E e) : It volition pushes an chemical component on stack represented past times this ArrayDeque.
  • E remove() : It volition take caput chemical component of the ArrayDeque.
  • boolean remove(Object o) : It volition take unmarried event of specified object from ArrayDeque.
  • E removeFirst() : It volition take initiatory off chemical component from ArrayDeque.
  • boolean removeFirstOccurrence(Object o) : It volition take initiatory off occurrence of the chemical component from ArrayDeque.
  • E removeLast() : It volition take final chemical component from ArrayDeque.
  • boolean removeLastOccurrence(Object o) : It volition take final occurrence of the chemical component from ArrayDeque.
  • int size() :It volition render size of ArrayDeque.
  • Object[] toArray() : It volition render elements array from ArrayDeque.
  • <T> T[] toArray(T[] a) : It volition render elements array from ArrayDeque. The runtime type of the returned array is that of the specified array.
Below given representative volition present yous demo of inward a higher house ArrayDeque  method's usage.

ArrayDeque Example
package JAVAExamples;  import java.util.ArrayDeque; import java.util.Deque;  world degree ArrayDequeExample {   world static void main(String[] args) {   // Create ArrayDeque.   ArrayDeque<String> d = novel ArrayDeque<String>();   // Add elements inward Deque.   d.add("one");   d.add("two");   d.add("three");   d.add("four");   d.add("five");   d.add("four");   d.add("six");   // Print Deque elements.   System.out.println("Deque elements are : " + d);    // Add chemical component at initiatory off of Deque.   d.addFirst("First Added");   System.out.println("Deque elements subsequently addFirst are : " + d);    // Add chemical component at final of Deque.   d.addLast("Last Added");   System.out.println("Deque elements subsequently addLast are : " + d);    // Get initiatory off chemical component from Deque.   System.out.println("First chemical component inward deque is : " + d.getFirst());    // Get final chemical component from Deque.   System.out.println("Last chemical component inward deque is : " + d.getLast());    // Get initiatory off chemical component from Deque using peek.   System.out.println("First chemical component inward deque using peek is : " + d.peek());    // Get final chemical component from Deque using peekLast.   System.out.println("Last chemical component inward deque using peekLast is : " + d.peekLast());    // Remove initiatory off chemical component from deque.   d.removeFirst();   System.out.println("Deque elements subsequently removeFirst are  : " + d);    // Using pop.   d.pop();   System.out.println("Deque elements subsequently popular are  : " + d);    // Using push.   d.push("First");   System.out.println("Deque elements subsequently force are  : " + d);    // Remove LastOccurrence of chemical component from deque using removeLastOccurrence.   d.removeLastOccurrence("four");   System.out.println("Deque elements subsequently removeLastOccurrence are  : "+ d);    // Get size of deque.   System.out.println("Size of Deque is  : " + d.size());  } }

Output :
Deque elements are : [one, two, three, four, five, four, six] Deque elements subsequently addFirst are : [First Added, one, two, three, four, five, four, six] Deque elements subsequently addLast are : [First Added, one, two, three, four, five, four, six, Last Added] First chemical component inward deque is : First Added Last chemical component inward deque is : Last Added First chemical component inward deque using peek is : First Added Last chemical component inward deque using peekLast is : Last Added Deque elements subsequently removeFirst are  : [one, two, three, four, five, four, six, Last Added] Deque elements subsequently popular are  : [two, three, four, five, four, six, Last Added] Deque elements subsequently force are  : [First, two, three, four, five, four, six, Last Added] Deque elements subsequently removeLastOccurrence are  : [First, two, three, four, five, six, Last Added] Size of Deque is  : 7


More interesting articles here :Generation Enggelmundus Internet Marketing Tool here :Zeageat IM http://www.software-testing-tutorials-automation.com/
Post a Comment (0)
Previous Post Next Post