WEB开发网
开发学院WEB开发Jsp Robocode的线程与执行次序 阅读

Robocode的线程与执行次序

 2008-01-05 10:37:51 来源:WEB开发网   
核心提示:Here are two methods that allow you to remove duplicates in an ArrayList. removeDuplicate does not maintain the order where as removeDuplicateWithOrder maintain

  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);
  }

Tags:Robocode 线程 执行

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接