Java Collection Difference getSymmetricDifference(final Set firstCollection, final Set secondCollection)

Here you can find the source of getSymmetricDifference(final Set firstCollection, final Set secondCollection)

Description

Finds all unique property names that are in the first set, but not in the second

License

Apache License

Parameter

Parameter Description
firstCollection - Set of property names
secondCollection - Set of property names

Return

- unique property names that are present in the first set but not in the second

Declaration

public static List<String> getSymmetricDifference(final Set<String> firstCollection,
        final Set<String> secondCollection) 

Method Source Code


//package com.java2s;
/*//from   w w  w .ja  v a  2s . co  m
 *  Inspired by the Commons Collections package created by Apache
 *  http://commons.apache.org/collections/
 *  http://www.apache.org/licenses/LICENSE-2.0
 */

import java.util.*;

public class Main {
    /**
     * Finds all unique property names that are in the first set, but not in the second
     * @param firstCollection - Set of property names
     * @param secondCollection - Set of property names
     * @return - unique property names that are present in the first set but not in the second
     */
    public static List<String> getSymmetricDifference(final Set<String> firstCollection,
            final Set<String> secondCollection) {
        List<String> difference = new ArrayList<String>(firstCollection);
        for (String value : secondCollection) {
            difference.remove(value);
        }
        return difference;
    }
}

Related

  1. difference(Collection a, Collection b)
  2. difference(final Collection c1, final Collection c2)
  3. difference(final Collection c1, final Collection c2)
  4. differentNull(Collection collection)
  5. getIntersectAndDiffs(Collection a, Collection b, Comparator comparator)
  6. leftDifference(final Collection c1, final Collection c2)