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


查看全文
  • 相关阅读:
    USACO Section 1.3 : Mixing Milk
    USACO Section 1.3 : Prime Cryptarithm
    USACO Section 1.2 : Name That Number
    USACO Section 1.3 : Calf Flac
    USACO Section 1.2 : Palindromic Squares
    Global.asax详解
    sql语句字符串处理大全
    ASP.net:URL重写实现IHttpHandler接口
    asp.net中使用基于角色role的Forms验证
    时间Table.TransformColumns(Power Query 之 M 语言)
  • 原文地址:https://www.cnblogs.com/ldxsuanfa/p/10925017.html
  • Copyright © 2011-2022 走看看