zoukankan      html  css  js  c++  java
  • Java 去除List列表中的重复项

       /**
           * Remove list duplicate item
         * 
         * @param srcList
         * @return
         */
        private static ArrayList<ResolveInfo> removeListDuplicateItemWithOrder(
                List<ResolveInfo> srcList) {
            ArrayList<ResolveInfo> mResolveInfoList = new ArrayList<ResolveInfo>();
            ArrayList<String> mPkgNameList = new ArrayList<String>();
            for (ResolveInfo resolveInfo : srcList) {
                String pkgName = resolveInfo.activityInfo.packageName;
                XLog.d(TAG, "removeListDuplicateWithOrder,pkgName=" + pkgName);
                // remove duplicate package name
                if (!mPkgNameList.contains(pkgName)) {
                    mPkgNameList.add(pkgName);
                    mResolveInfoList.add(resolveInfo);
                }
            }
    
            if (DEBUG_MODE) {
                for (ResolveInfo resolveInfo : mResolveInfoList) {
                    XLog.d(TAG, "kkkk,removeDuplicateWithOrder,resolveInfo="
                            + resolveInfo);
                }
            }
            return mResolveInfoList;
        }
    
        /**
         * Remove list duplicate item
         * 
         * @param srcList
         * @return
         */
        private static ArrayList<String> removeListDuplicateItemWithOrder(
                ArrayList<String> srcList) {
            ArrayList<String> desList = new ArrayList<String>();
            for (String src : srcList) {
                XLog.d(TAG, "removeListDuplicateWithOrder,src=" + src);
                if (!desList.contains(src)) {
                    desList.add(src);
                }
            }
    
            if (DEBUG_MODE) {
                for (String des : desList) {
                    XLog.d(TAG, "removeDuplicateWithOrder,des=" + des);
                }
            }
            return desList;
        }
    
        /**
         * Remove liset duplicate item
         * 
         * @param srcList
         * @return
         */
        private static Set removeListDuplicateItemWithOrder2(
                ArrayList<String> srcList) {
            Set mLinkedHashSet = new LinkedHashSet<String>();
            mLinkedHashSet.add(srcList);
            for (Iterator iterator = mLinkedHashSet.iterator(); iterator.hasNext();) {
                String element = (String) iterator.next();
                XLog.d(TAG, "removeListDuplicateWithOrder2,element=" + element);
            }
            return mLinkedHashSet;
        }
  • 相关阅读:
    自己开发网站全文检索系统
    中国摇滚二十年(经典100首歌曲)
    有一首歌
    Snoopy.class.php使用手册
    wp-Syntax 插件使用方法
    rabbitmq使用
    小程序相关功能的实现
    知识链接
    celery使用
    阿里云服务器部署项目注意事项
  • 原文地址:https://www.cnblogs.com/onelikeone/p/7582689.html
Copyright © 2011-2022 走看看