Here you can find the source of containSameElements(Collection
public static <T> boolean containSameElements(Collection<Set<T>> sets)
//package com.java2s; //License from project: Open Source License import java.util.Collection; import java.util.Iterator; import java.util.Set; public class Main { public static <T> boolean containSameElements(Collection<Set<T>> sets) { if (sets.isEmpty() || sets.size() < 2) return false; Iterator<Set<T>> iterator = sets.iterator(); Set<T> basicSet = iterator.next(); Set<T> actualSet;//from w w w . j a v a 2 s.c om while (iterator.hasNext()) { actualSet = iterator.next(); if (actualSet.size() != basicSet.size()) return false; if (!actualSet.containsAll(basicSet)) return false; } return true; } public static <T> boolean containSameElements(Set<T>... sets) { if (sets.length == 0 || sets.length < 2) return false; Set<T> basicSet = sets[0]; for (int i = 1; i < sets.length; i++) { if (sets[i].size() != basicSet.size()) return false; if (!sets[i].containsAll(basicSet)) return false; } return true; } }