zoukankan      html  css  js  c++  java
  • 两种方法删除ArrayList里反复元素

    方法一:

    /** List order not maintained **/
    
      public static void removeDuplicate(ArrayList arlList)
      {
       HashSet h = new HashSet(arlList);
       arlList.clear();
       arlList.addAll(h);
      }
    
    
    方法二:


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


查看全文
  • 相关阅读:
    【C++学习】C++中的new VS C语言中的malloc
    【C++学习】多态——解析树实例分析
    【C++错误处理】multiple definition of
    VS.NET控件命名规范
    ASP.NET跨页面传值技巧总结
    marquee+js实现某个区域的“无缝滚动效果”
    vs2008与oracle数据库连接
    C#中HashTable的用法
    1. asp.net实现单点登陆
    GridView实现某列中相同值合并(不规则表)
  • 原文地址:https://www.cnblogs.com/ldxsuanfa/p/10925017.html
  • Copyright © 2011-2022 走看看