set Multiplication for string set - Java java.lang

Java examples for java.lang:String Repeat

Description

set Multiplication for string set

Demo Code


//package com.java2s;

import java.util.HashSet;

import java.util.Set;

public class Main {
    public static Set<Set<String>> setMultiplication(
            Set<String>... setsArray) {
        if (setsArray == null || setsArray.length == 0) {
            return null;
        }//from   www  .  j  av  a 2s  . c  om
        return setMultiplication(0, setsArray);
    }

    private static Set<Set<String>> setMultiplication(int index,
            Set<String>... setsArray) {
        Set<Set<String>> setsMultiplied = new HashSet<Set<String>>();
        if (index == setsArray.length) {
            setsMultiplied.add(new HashSet<String>());
        } else {
            for (String obj : setsArray[index]) {
                for (Set<String> set : setMultiplication(index + 1,
                        setsArray)) {
                    set.add(obj);
                    setsMultiplied.add(set);
                }
            }
        }

        return setsMultiplied;
    }
}

Related Tutorials