「Java入門」Java.util.ArrayDeque.clear() のサンプルコード
Javaコード
import java.util.ArrayDeque;
import java.util.Deque;
public class ArrayDequeDemo {
public static void main(String[] args) {
// create an empty array deque with an initial capacity
Deque<Integer> cft = new ArrayDeque<Integer>(8);
// use add() method to add elements in the deque
cft.add(44);
cft.add(35);
cft.add(24);
cft.add(88);
// let us print all the elements available in deque
for (Integer number : cft) {
System.out.println(“Number = " + number);
}
// finding size of this deque
int k = cft.size();
System.out.println(“Befor deque consists of “+ k +" elements");
System.out.println(“Performing clear operation !!");
cft.clear();
k = cft.size();
System.out.println(“After deque consists of “+ k +" elements");
}
}
実行結果
Number = 44
Number = 35
Number = 24
Number = 88
Befor deque consists of 4 elements
Performing clear operation !!
After deque consists of 0 elements