One of the common questions I hear from Java newcomers is - where is a FIFO list in Java?一個共同的問題,我聽到從Java新人是-那裡是一個F IFO的名單在J ava呢?

Java does have a FIFO list capability built-in with LinkedList and ArrayList, but they are not well advertized.華確有FIFO的名單,能力內建在與linkedlist和ArrayList的,但他們不是好advertized 。

A FIFO interface should at least have: 1 FIFO的接口,至少應該有:

 public interface FIFO {     /** Add an object to the end of the FIFO queue */     boolean add(Object o);      /** Remove an object from the front of the FIFO queue */     Object remove();      /** Return the number of elements in the FIFO queue */     int size(); } 公共接口的FIFO ( / **添加對象到去年底的FIFO隊列* /布爾添加(對象海外) ; / **刪除一個對象從前面的FIFO隊列* /對象刪除( ) ; / **返回元素個數在FIFO隊列* /詮釋大小( ) ; ) 

A FIFOList class implementing the above would simply be: 1 fifolist級執行上述僅僅是:

 public class FIFOList extends LinkedList implements FIFO {     public Object remove() {         return remove(0);     } } 公共類fifolist延伸linkedlist實行FIFO的(公共對象刪除( ) (返回刪除( 0 ) ; ) ) 

I prefer this setup instead of using a LinkedList.remove(0) directly.我喜歡這種體制而不是使用linkedlist.remove ( 0 )直接。 It looks cleaner.看來,清潔。

BTW: You can also extend an ArrayList instead of LinkedList to achieve the same functionality.的BTW :您也可以延長一個ArrayList而不是linkedlist要達到相同的功能。 LinkedList should in theory provide better performance. linkedlist應在理論提供更好的表現。