龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 软件开发 > JAVA开发 >

Robocode的线程与执行次序

时间:2009-12-23 15:42来源:未知 作者:admin 点击:
分享到:
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. 1.The removeDuplicate Method: /** Li

  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.
  1.The removeDuplicate Method:
  /** List order not maintained **/
  public static void removeDuplicate(ArrayList arlList)
  {
    HashSet h = new HashSet(arlList);
    arlList.clear();
    arlList.addAll(h);
  }
  
  2.The removeDuplicateWithOrder Method:
  /** List order maintained **/
  public static void removeDuplicateWithOrder(ArrayList arlList)
  {
    Set set = new HashSet();
    List newList = new ArrayList();
    for (Iterator iter = arlList.iterator(); iter.hasNext(); )
    {
   Object element = iter.next();
   if (set.add(element)) newList.add(element);
    }
    arlList.clear();
    arlList.addAll(newList);
  }
  
精彩图集

赞助商链接