Java SE: Tips_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > Java SE: Tips

Java SE: Tips

 2014/8/28 15:22:35  DavyJones2010  程序员俱乐部  我要评论(0)
  • 摘要:1.HowtocompareequalsfortwoList:1>Writingboilerplatecode2>Usingorg.apache.commons.collections.ListUtils.isEqualList()publicstaticbooleanisEqualList(finalCollectionlist1,finalCollectionlist2){if(list1==list2){returntrue;}if(list1==null|
  • 标签:Java

1. How to compare equals for two List:

? ? 1> Writing boiler plate code

? ? 2> Using org.apache.commons.collections.ListUtils.isEqualList()

class="java" name="code">public static boolean isEqualList(final Collection list1, final Collection list2) {
    if (list1 == list2) {
        return true;
    }
    if (list1 == null || list2 == null || list1.size() != list2.size()) {
        return false;
    }

    Iterator it1 = list1.iterator();
    Iterator it2 = list2.iterator();
    Object obj1 = null;
    Object obj2 = null;

    while (it1.hasNext() && it2.hasNext()) {
        obj1 = it1.next();
        obj2 = it2.next();

        if (!(obj1 == null ? obj2 == null : obj1.equals(obj2))) {
            return false;
        }
    }

    return !(it1.hasNext() || it2.hasNext());
}

?

2. How to compare equals for two Set:

? ? 1> Using org.apache.commons.collections.SetUtils.isEqualSet()

?

发表评论
用户名: 匿名