I have started implementing a TreeSet in java.
i wish to knows, is it possible to create a set within a set.
For example i need to create a set that gives output
{{1,2,3,4,5,6,7,8},(1,{1,2,3,4,5,6,7,8})}
The problem is that i can’t get add to my sets to give the desired output.
I have even tried putting my treeset within an arraylist.
ArrayList<TreeSet<Integer>> SET = new ArrayList<TreeSet<Integer>>();
this still doesn’t give me my desired result, and makes my code really complicated.
as you can see, the output has 2 sets that are basically elements of a larger set.
Please can anyone help?
I AM NOT ASKING FOR CODE ONLY ADVICE!!!
TreeSet<T>needs a comparator onTin order to arrange the elements inside it. You can cerate aTreeSetwith a custom comparator that “understands” how to compareTreeSets. This will let the outer tree set decide on the order of the tree sets that you put inside it: