Java--Using the Deque Interface

1.working with the ArrayDeque Class

 1 package self;
 2 
 3 import java.util.ArrayDeque;
 4 
 5 //import java.util.Hashtable;
 6 
 7 public class ArrayDequeDemo {
 8     public static void main(String args[]) {
 9         ArrayDeque<Double> obj = new ArrayDeque<Double>();
10         Double dobj1 = new Double(7.5);
11         Double dobj2 = new Double(8.5);
12         Double dobj3 = new Double(9.5);
13         Double dobj4 = new Double(10.5);
14 
15         System.out.println("Size of ArrayDeque is :" + obj.size());
16 
17         obj.add(dobj1);
18         obj.add(dobj2);
19 
20         System.out.println("
ArrayDeque after adding the objects:" + obj);
21         System.out.println("Size of ArrayDeque after adding objects " + obj.size());
22 
23         obj.addFirst(dobj3);
24         obj.addFirst(dobj4);
25 
26         System.out.println("ArrayDeque after adding the objects at first and last  " + obj);
27         System.out.println("Size of ArrayDeque after adding objects at first and last " + obj.size());
28 
29         obj.removeFirst();
30         System.out.println("
ArrayDeque after removing the first object:" + obj);
31         System.out.println("Size of ArrayDeque after removing the first objects " + obj.size());
32 
33     }
34 }
View Code

测试结果:

原文地址:https://www.cnblogs.com/Catherinezhilin/p/8990129.html