compare Two Collections for Equality - Java java.util

Java examples for java.util:Collection Compare

Description

compare Two Collections for Equality

Demo Code


//package com.java2s;
import java.util.Collection;

public class Main {
    public static void main(String[] argv) {
        Collection expectedAffectedFiles = java.util.Arrays.asList("asdf",
                "java2s.com");
        Collection affectedFiles = java.util.Arrays.asList("asdf",
                "java2s.com");
        System.out.println(compareTwoCollectionsEquality(
                expectedAffectedFiles, affectedFiles));
    }// w  ww .  ja v a2 s.co m

    /**
     * 
     * @param expectedAffectedFiles
     * @param affectedFiles
     * @return
     */
    public static boolean compareTwoCollectionsEquality(
            Collection<String> expectedAffectedFiles,
            Collection<String> affectedFiles) {
        int counter = 0;
        for (String f1 : affectedFiles) {
            for (String f2 : expectedAffectedFiles) {
                if (f1.equals(f2)) {
                    counter++;
                }
            }
        }
        return expectedAffectedFiles.size() == counter;
    }
}

Related Tutorials