首页 > 学院 > 开发设计 > 正文

Robocode的线程与执行次序

2019-11-18 12:21:24
字体:
来源:转载
供稿:网友

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

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表