判断两个集合的值是否相等

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/le9406/article/details/102686007
 /**
     * 
     * @param list1  集合1
     * @param list2  集合2
     * @param <T>    数据类型
     * @return
     */
    private <T> boolean compareList(List<T> list1, List<T> list2) {
        if (list1 == null) {
            return false;
        }
        if (list1.size() != list2.size()) {
            return false;
        }

        Set<Integer> hashCodeSet = new HashSet<>();
        for (T adInfoData : list1) {
            hashCodeSet.add(adInfoData.hashCode());
        }
        for (T adInfoData : list2) {
            if (!hashCodeSet.contains(adInfoData.hashCode())) {
                return false;
            }
        }
        return true;
    }

猜你喜欢

转载自blog.csdn.net/le9406/article/details/102686007