public class Subset { @SafeVarargs public static List> subsets(T... items) { List elements = new ArrayList<>(new HashSet<>(Arrays.asList(items))); List> results = new ArrayList<>(); for (T e : elements) { // Record size as the list will change int size = results.size(); for (int i = 0; i < size; i++) { List subset = new ArrayList<>(results.get(i)); subset.add(e); results.add(subset); } results.add(Collections.singletonList(e)); } return results; } public static void main(String[] args) { List> results = subsets("a", "b", "c"); for (List result : results) { System.out.println(result); } } }