熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Java高級技術 >> 正文

Robocode的線程與執行次序

2022-06-13   來源: Java高級技術 

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

From:http://tw.wingwit.com/Article/program/Java/gj/201311/27380.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.