Code: FIFO List in Java編號: FIFO的名單在Java
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應在理論提供更好的表現。
Filed under提起下 Headline News頭條新聞 , , How To如何 , , Java Software Java軟件 , , Tech Note技術說明 | |
| |
RSS 2.0 2.0 | |
Email this Article電子郵件此文章
You may also like to read您也可以想讀 |




February 26th, 2006 at 11:04 am 2006年2月26日在上午11時04分
A nice solution for a FIFO queue is a wrapper around a circular array.好一個解決方案的FIFO隊列是一個圍繞一圓形陣列。 Removes at either end are cheap, inserts at either end are also cheap.刪除兩端也很便宜,插入兩端也便宜。 Memory usage is low and Object allocation is infrequent.記憶體使用量低,分配對象是屢見不鮮。
February 26th, 2006 at 7:54 pm 2006年2月26日在下午7點54分
well..以及.. isnt fifo is actually a Queue? isn't FIFO的其實是一個隊列? there are plenty of Queues available in Java5.有很多人龍可在java5 。
February 27th, 2006 at 9:07 am 2006年2月27日在上午09時07分
You are right.你說得對。 I overlooked them in 1.5. i忽略了他們在五月一日。 In fact ArrayList also implements Queue.事實上, ArrayList中還執行隊列中。
February 17th, 2008 at 6:14 pm 2008年2月17日在下午6時14分
can you send me a copy of your codes in FIFO which deals with the page(s).你能寄給我一份您的代碼在FIFO的處理與網頁( ) 。 please grant me my request..thank you.!!!請給予我的要求..謝謝。 !
April 26th, 2008 at 1:41 pm 2008年4月26日在下午1時41分
You could have just used LinkedList.你可能只是用來linkedlist 。 Method add adds element to the end.方法添加元素加入到去年底。 And to retrieve element use getFirst和檢索元素使用getfirst
April 27th, 2008 at 1:21 am 2008年4月27日在上午01時21分
As I said before:正如我以前說過:
“I prefer this setup instead of using a LinkedList.remove(0) directly. “我喜歡這種體制而不是使用linkedlist.remove ( 0 )直接。 It looks cleaner.”看來,清潔“ 。
May 25th, 2008 at 6:39 pm 2008年5月25日在下午6時39分
Muchas gracias! muchas格拉西亞!
you’r right, it is simple and clear you'r的權利,這是簡單而明確