Hai Kushtwar,

Arrays.sort uses Modified MergeSort algorithm for sorting and API says that it does it in natural ordering of the element and ordering means it has to make some sense rather than random arrangement and the API specifys that it arranges it in ascending order so based on this best way to understand it is using bubble sort

as it is the simplest sorting algorithm useful for small list

{person[0],person[1],person[2]} well with natural ordering i.e least will be first so

person[0].compareTo(person[1]) which returns 1 think like >0,0,<0 rather than 1 , 0, -1 as you will get the same output if you return 1,11,11121.... any postive number greater than 0(ofcourse has to be compatible with int

)

so person[0] is greater than person[1] now according to bubble sort swap them

then you will have

{person[1],person[0],person[2]}

now person[0].compareTo(person[2]) which is also positive so person[0] is greatest of three so now list will be

{person[1],person[2],person[0]}

now person[1].compareTo(person[2]) and person[1] is greater than person[2] so the least is person[2] and obviously the list will be

{person[2],person[1],person[0]}

now using the same

least will be first principle if negative number is returned from compareTo then person[0] will be the least then successive comparasion will be same and thus no effect it is the same with 0

I hope you understood