public static < T > Set < T > union ( Collection < Set < T > > sets ) { Set < T > result = new HashSet <> ( ) ; if ( sets . isEmpty ( ) ) { return result ; } Iterator < Set < T > > iter = sets . iterator ( ) ; result . addAll ( iter . next ( ) ) ; if ( sets . size ( ) == 1 ) { return result ; } while ( iter . hasNext ( ) ) { result . addAll ( iter . next ( ) ) ; } return result ; }
Determines the union of a collection of sets .