【Java】コレクション ~ Queue 編~

Queue

`#`キュー備考
1ArrayBlockingQueue固定要領の配列に基づくキュー
2LinkedBlockingQueue
3PriorityBlockingQueue
4SynchronousQueue
5PriorityQueue優先順位で並べ替えるキュー
6DelayQueue時間後経過しなければ要素を取り出すことの出来ないキュー
7ConcurrentLinkedQueue

サンプル

import java.util.concurrent.ArrayBlockingQueue;

public class SampleQueue {
	public static void main(String[] args) {
		ArrayBlockingQueue<Integer> queues =
				new ArrayBlockingQueue<Integer>(100);
		for (int i = 0; i < 5; i++) {
			System.out.println("offer() : " + queues.offer(i) + " : " + queues);
		}

		for (int i = 0; i < 7; i++) {
			System.out.println("peek() : " + queues.peek() + " : " + queues);
			System.out.println("poll() : " + queues.poll());
		}
	}
}

出力結果

offer() : true : [0]
offer() : true : [0, 1]
offer() : true : [0, 1, 2]
offer() : true : [0, 1, 2, 3]
offer() : true : [0, 1, 2, 3, 4]
peek() : 0 : [0, 1, 2, 3, 4]
poll() : 0
peek() : 1 : [1, 2, 3, 4]
poll() : 1
peek() : 2 : [2, 3, 4]
poll() : 2
peek() : 3 : [3, 4]
poll() : 3
peek() : 4 : [4]
poll() : 4
peek() : null : []
poll() : null
peek() : null : []
poll() : null

参考文献

http://www.atmarkit.co.jp/fjava/javatips/182java064.html
http://nextindex.s141.xrea.com/java/collection/Queue.html
http://www.javadrive.jp/start/linkedlist/index5.html
http://www.techscore.com/tech/Java/JavaSE/Utility/12/#utl12-2

カスタムソート

 * 以下の関連記事を参照のこと
http://blogs.yahoo.co.jp/dk521123/32156111.html

関連記事

コレクション ~ List 編~

http://blogs.yahoo.co.jp/dk521123/32156111.html

コレクション ~ Map編~

http://blogs.yahoo.co.jp/dk521123/33002154.html

コレクション ~ Set 編~

http://blogs.yahoo.co.jp/dk521123/33006348.html

コレクション ~ Queue 編~

http://blogs.yahoo.co.jp/dk521123/33006366.html

コレクション ~ Deque 編~

http://blogs.yahoo.co.jp/dk521123/36352193.html

コレクション ~ マルチスレッド 編~

http://blogs.yahoo.co.jp/dk521123/34006868.html

【非同期】Producer-Consumer パターン

http://blogs.yahoo.co.jp/dk521123/32914080.html