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


查看全文
  • 相关阅读:
    关于Python的面试题
    Python爬虫框架Scrapy学习笔记原创
    Python交互数据库(Mysql | Mongodb | Redis)
    后端程序员必备的Linux基础知识
    python的多路复用实现聊天群
    Python发送邮件(最全)
    7行Python代码的人脸识别
    python所遇到的坑
    Python图形界面开发—wxPython库的布局管理及页面切换
    机器学习:数据预处理之独热编码(One-Hot)
  • 原文地址:https://www.cnblogs.com/ldxsuanfa/p/10925017.html
  • Copyright © 2011-2022 走看看