I needed to sort elements for which I used Arrays.sort() function. I read somewhere that it sorts in O(nlogn) time only for arrays containing objects as elements (Integer, Double, etc. but not int, double). But when I was comparing elements in the array after sorting, it showed some weird behaviour. Comparing elements upto 127, it compares correctly but after that it gives wrong results. Any reason as to why?
Here is my code where seq[] is an Integer array (and not int seq[]):
if(seq[i]!=seq[i-1]) map.put(seq[i],count++);








Do you know the difference between == and equals()?
Integers in range [-128, 127] are created in advance and are taken from cache, while other Integer objects are created newly every time.
Oh ok. Thanks. Yes I know the difference between the two but I tend to use equals() only with strings. That's why didn't notice that. Thanks a lot for pointing out :)
For Integer comparisons, use the method intValue()