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


查看全文
  • 相关阅读:
    微信红包开发
    第一次开博客,留此纪念
    数据结构--树(遍历,红黑,B树)
    c++之vector
    动态规划求解最长公共子序列问题
    c++之map
    k-折交叉验证(k-fold crossValidation)
    prim算法
    快速排序算法
    浙大机试题目
  • 原文地址:https://www.cnblogs.com/ldxsuanfa/p/10925017.html
  • Copyright © 2011-2022 走看看