1. 程式人生 > >Java 去除List列表中的重復項

Java 去除List列表中的重復項

contain col next pre pac for sta java std

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

Java 去除List列表中的重復項