您可以将a LinkedList用作队列:
Queue<String> qe=new LinkedList<String>();
qe.add("b");
qe.add("a");
qe.add("c");
qe.add("e");
qe.add("d");
Iterator it=qe.iterator();
System.out.println("Initial Size of Queue :"+qe.size());
while(it.hasNext())
{
String iteratorValue=(String)it.next();
System.out.println("Queue Next Value :"+iteratorValue);
}
// get value and does not remove element from queue
System.out.println("Queue peek :"+qe.peek());
// get first value and remove that object from queue
System.out.println("Queue poll :"+qe.poll());
System.out.println("Final Size of Queue :"+qe.size());
Run Code Online (Sandbox Code Playgroud)
如果您还想添加优先级,可以使用 PriorityQueue
如果您需要它是线程安全使用 ConcurrentLinkedQueue
另外,正如@Leonidos所说,你可以使用a ByteBuffer,你需要低级I/O,但要小心.
如果您需要有关如何使用它们的任何说明,请随时评论该帖子.
| 归档时间: |
|
| 查看次数: |
7899 次 |
| 最近记录: |