电脑故障

位置:IT落伍者 >> 电脑故障 >> 浏览文章

Robocode的线程与执行次序


发布日期:2018/10/18
 

Here are two methods that allow you to remove duplicates in an ArrayList removeDuplicate does not maintain the order where as removeDuplicateWithOrder maintains the order with some performance overhead

The removeDuplicate Method:

/** List order not maintained **/

public static void removeDuplicate(ArrayList arlList)

{

HashSet h = new HashSet(arlList);

arlListclear();

arlListaddAll(h);

}

The removeDuplicateWithOrder Method:

/** List order maintained **/

public static void removeDuplicateWithOrder(ArrayList arlList)

{

Set set = new HashSet();

List newList = new ArrayList();

for (Iterator iter = erator(); iterhasNext(); )

{

Object element = iternext();

if (setadd(element)) newListadd(element);

}

arlListclear();

arlListaddAll(newList);

}

上一篇:多线程中的死锁举例与分析

下一篇:Flyweight(享元)模式