Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Arraydeque Java Code With Examples

Program

import java.util.ArrayDeque;
import java.util.Deque;

public class ArrayDequeExample {
	public static void main(String[] args) {
		Deque ven1 = new ArrayDeque();
		
		//add​(E e)
		ven1.add(28);
		ven1.add(25);
		ven1.add(26);
		System.out.println("mark list of student1:" + ven1);
		
		// addAll​(Collection extends E> c)
		Deque ven2 = new ArrayDeque();
		ven2.add(22);
		ven2.add(19);
		ven2.add(20);
		System.out.println(" \nmark list of student2:" + ven2);
		ven1.addAll(ven2);
		System.out.println("\nThe total list of student mark : " + ven1);
		
		//peek()
		int ret = ven1.peek();
		System.out.println("\npeeked Element is: " + ret);
		System.out.println("\nArrayDeque: " + ven1);
		
		//poll()
		int reg = ven1.poll();
		System.out.println("\npolled Element is: " + reg);
		System.out.println("\nArrayDeque: " + ven1);

 		//isEmpty()
		System.out.println("\nIs ArrayDeque Empty: "+ven1.isEmpty());
	}
}

Output

mark list of student1:[28, 25, 26]
 
mark list of student2:[22, 19, 20]

The total list of student mark : [28, 25, 26, 22, 19, 20]

peeked Element is: 28

ArrayDeque: [28, 25, 26, 22, 19, 20]

polled Element is: 28

ArrayDeque: [25, 26, 22, 19, 20]

Is ArrayDeque Empty: false  

Description

public boolean add​(E e)

Inserts the specified Element at the end of this Deque.
This method is equivalent to addLast(E).

Parameters:

e – the element to add

Returns:

true (as specified by Collection.add(E))

Throws:

NullPointerException – if the specified element is null

public boolean addAll​(Collection extends E> c)

Adds all of the elements in the specified collection at the end of this deque, as if by calling addLast(E) on each one, in the order that they are returned by the collection’s iterator.

Parameters:

c – the elements to be inserted into this deque

Returns:

true if this deque changed as a result of the call

Throws:

NullPointerException – if the specified collection or any of its elements are null

public E peek()

Retrieves, but does not remove, the head of the queue represented by this deque, or returns null if this deque is empty.
This method is equivalent to Deque.peekFirst().

Specified by:

peek in interface Deque

Specified by:

peek in interface Queue

Returns:

the head of the queue represented by this deque, or null if this deque is empty

public E poll()

Retrieves and removes the head of the queue represented by this deque (in other words, the first element of this deque), or returns null if this deque is empty.
This method is equivalent to Deque.pollFirst().

Specified by:

poll in interface Deque

Specified by:

poll in interface Queue

Returns:

the head of the queue represented by this deque, or null if this deque is empty

public boolean isEmpty()

Returns true if this deque contains no elements.

Specified by:

isEmpty in interface Collection

Overrides:

isEmpty in class AbstractCollection

Returns:

true if this deque contains no elements

The post Arraydeque Java Code With Examples appeared first on Candidjava -Core Java, Servlet, Jsp, Hibernate,Spring,.



This post first appeared on Core Java,Servlet,Jsp,Struts,Hibernate,Spring Fram, please read the originial post: here

Share the post

Arraydeque Java Code With Examples

×

Subscribe to Core Java,servlet,jsp,struts,hibernate,spring Fram

Get updates delivered right to your inbox!

Thank you for your subscription

×