「Java入門」java.util.ArrayDeque.offerFirst()のサンプルコード

Javaコード

import java.util.ArrayDeque;

import java.util.Deque;

public class ArrayDequeofferFirssDeno {

public static void main(String[] args) {
// create an empty array deque with an initial capacity
Deque<Integer> deque = new ArrayDeque<Integer>(8);

// use add() method to add elements in the deque
deque.add(12);
deque.add(23);
deque.add(28);
deque.add(45);

// this will insert 10 at the front
deque.offerFirst(20);

System.out.println(“実行結果:\n");
// printing all the elements available in deque
for (Integer number : deque) {
System.out.println(“Number = " + number);
}
}

}

実行結果:

Number = 20
Number = 12
Number = 23
Number = 28
Number = 45

Java

Posted by arkgame