charla Vella wrote:thanks Nir, have another query please
it says that this program should output, "40 200 60 -2", followed by an exception
the reason being is that Arrays.sort() assumes that the elements of the array to be sorted implement comparable unless you provide a Comparator.
I am a bit confused can anyone please explain this to me thanks
The exception you were getting was because of the statement-Arrays.sort(vla); Here, you were trying to sort the Array using the compareTo() in Comparable interface which is by default and is only used unless you don't define an external method compare() from Comparator interface for SORTING by some other logic or by other parameters.
Try this code and the output you would get is,
40 200 60 -2
40 60 200 1
This will help you understand better!