Java List Equal isEqualAsMultiset(List left, List right)

Here you can find the source of isEqualAsMultiset(List left, List right)

Description

Checks whether two given lists that are interpreted as multi-sets contain the same elements.

License

Open Source License

Parameter

Parameter Description
left A list.
right Another list.

Return

True if and only if both lists contain equal elements including repetitions.

Declaration

public static boolean isEqualAsMultiset(List<?> left, List<?> right) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.List;

public class Main {
    /**//  www. ja  v a  2  s. c o m
     * Checks whether two given lists that are interpreted as multi-sets contain the same elements.
     * The provided lists may be altered during this check.
     *
     * @param left  A list.
     * @param right Another list.
     * @return True if and only if both lists contain equal elements including repetitions.
     */
    public static boolean isEqualAsMultiset(List<?> left, List<?> right) {

        for (Object e : left) {

            if (right.contains(e)) {
                right.remove(e);
            } else {
                return false;
            }
        }

        return right.isEmpty();
    }
}

Related

  1. equalsBasedOnEntryIdentity(final List a, final List b)
  2. equalShallow(List list0, List list1)
  3. isEqual(Collection listA, Collection listB)
  4. isEqual(List list1, List list2)
  5. isEqual(List from, List to)
  6. isEqualIgnoringOrder(List left, List right)
  7. isEqualList(List list1, List list2)
  8. isEquals(List l1, List l2)
  9. isEquals(List l1, List l2)