這樣修改Linked list成hash,可能只是簡單的用new HashSet()代替new LinkedList()。就這樣。沒有其他的需要修改的地方。
作為另一個例子,比較下面兩段代碼:
f()
{
Collection c = new HashSet();
//...
g( c );
}
g( Collection c )
{
for( Iterator i = c.iterator(); i.hasNext() )
do_something_with( i.next() );
}
和
延伸閱讀
文章來源于領測軟件測試網 http://www.kjueaiud.com/