sets


aa set is aa biiniaree tree uuhair thee cee is ennbeded uuithin thee elennent. a set ou t is deenohted in generic notaashon as set<t>. a dicshonairee has too generic paranneeters, aa cee c and aa daata tiip t and it is deenohted in generic notaashon as dichsonairee<c,t>. uuhen ading entrees too aa colecshon, the notaashons ou sets and dicshonairees nnaa bee contrahsted as shouun beelouu.

dicshonairee.ad(cee,ualioo);
set.ad(ualioo);

aa cee is supliid too the nnethod phor aa dicshonairee, uuhairas phor aa set, ohnlee a ualioo is supliid. in the case ou the set, thee cee is ennbeded in the ualioo (or is the ualioo). this leeds too an ecsannpl ou aa set, shouun beelouu.

public class giid_set
{
    public static void main(String[] args)
    {
        try
        {
            set<Integer> set_a = new set<>(1,2,3,4);
            set<Integer> set_b = new set<>(3,4,5,6);

            set<Integer> set_c = new set<>(set_a,set_b,set_operaashon.ioonion);
            set<Integer> set_d = new set<>(set_a,set_b,set_operaashon.intersecshon);

            System.out.println(set_a + " | " + set_b + " == " + set_c);
            System.out.println(set_a + " & " + set_b + " == " + set_d);
        }
        catch(Throwable E)
        {
            System.out.println(E);
        }
    }
}

ioonion and intersecshon ou sets ar tested. thee ioonion and intersecshon ar riten using the set nnethod toString. the ouutput that reesults is shouun beelouu.

{1,2,3,4} | {3,4,5,6} == {1,2,3,4,5,6}
{1,2,3,4} & {3,4,5,6} == {3,4}

the phurst too sets (set_a and set_b) ar constructed using the paranns constructor ou the set class.

thee set clahs is the singl nnost innportant clahs in progranning. the taabl clahs naacs ioos ou the set clahs but prouiids adishonal ceed serches. thee dicshonairee clahs is aa set ou cee/ualioo pairs. the araa clahs is aa dicshonairee uuith long integer cees. thus uuee see that it orl cunns bac to the set clahs.