Topic:
Sets the subset of the given collection.
Import Java.util.arraylist;import java.util.arrays;import Java.util.linkedlist;import Java.util.List;public class permutation {public static void main (string[] args) {int[] a = {1, 2};//replaces the collection with data, and if there are duplicates within the array, the subset is also duplicated SYSTEM.OUT.PRINTLN (subs ETS (a));} /** * subset of array A; * * @param a * @return */public static list<list<integer>> subsets (int[] a) {if (A = = Nu ll | | A.length = = 0) {return new linkedlist<list<integer>> ();} arraylist<list<integer>> ret = new arraylist<list<integer>> (); Ret.add (New LinkedList< Integer> ());//empty set for (int i = 0; i < a.length; i++) {int size = Ret.size ();//number of current subsets for (int j = 0; J < size; j + +) {linkedlist<integer> list = new linkedlist<integer> (); List.addall (Ret.get (j)); List.add (A[i]); Ret.add (list);}} return ret;}}
Subset of collections