Click here to watch in Youtube :
https://www.youtube.com/watch?v=Op-7j3dAQCI&list=UUhwKlOVR041tngjerWxVccw
DequeExample.java
Output
https://www.youtube.com/watch?v=Op-7j3dAQCI&list=UUhwKlOVR041tngjerWxVccw
DequeExample.java
import java.util.Deque; import java.util.LinkedList; /* * Example of removeFirst() and pollFirst() methods. */ public class DequeExample { public static void main( String[] args ) { Deque<Integer> deque = new LinkedList<Integer>(); deque.add(100); deque.add(200); deque.add(300); System.out.println("deque : " + deque + "\n"); /* * Retrieves and removes the first element of this deque. This method * differs from pollFirst only in that it throws an exception if this * deque is empty. */ Integer removedElement = deque.removeFirst(); System.out.println("removedElement : " + removedElement); System.out.println("deque : " + deque + "\n"); /* * Retrieves and removes the first element of this deque, or returns * null if this deque is empty. */ removedElement = deque.pollFirst(); System.out.println("removedElement : " + removedElement); System.out.println("deque : " + deque + "\n"); } }
deque : [100, 200, 300] removedElement : 100 deque : [200, 300] removedElement : 200 deque : [300]
https://sites.google.com/site/javaee4321/java-collections/DequeDemoRemovePollFirst.zip?attredirects=0&d=1
See also:
No comments:
Post a Comment