服务热线:13616026886

技术文档 欢迎使用技术文档,我们为你提供从新手到专业开发者的所有资源,你也可以通过它日益精进

位置:首页 > 技术文档 > JAVA > 新手入门 > 基础入门 > 查看文档

robocode的线程与执行次序


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

扫描关注微信公众号