This week's giveaway is in the Android forum. We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line! See this thread for details.

Hi ranchers this is a code from ExamLab just edited a part to make it work.

I know that :
negative if objOne < objTwo
zero if objOne == objTwo
positive if objOne > objTwo

Here's my question:

how does the set arrange the elements?

Because as of now what I just know is:
if you compare the "1st argument to the 2nd argument" in compare method you get an natural order, or you get a duplicate
if you compare the "2nd argument to the 1st argument" in compare method you get an reverse order , or you get a duplicate

In this method does the set insert the 1st element I added comparing to the second element?

to simplify writing I set a1 = new A(1) and respectively a2, a3.

Now, when cs.add(a1) is performed, the objects a1 and a3 are compared. Actually it doesn't matter if compare(a1,a3) or
compare(a3,a1) is inoked, since in any case the comparison yields a1 < a3. For:

compare(a1,a3) yields -1, meaning a1 < a3.
compare(a3,a1) yields +1, meaning a3 > a1, which is equivalent to a1 < a3.

So after adding a1, the order of cs is {a1,a3}.

When adding a2, the three elements a1, a2, a3 are compared, yielding the order {a1,a2,a3}.