I want to see if an array already has sorted elements.
I tried a simple:
Also tried to do it with equals method and without a toString method but the fact is sort returns void so it cannot be compared. What to do in this case?
posted 9 months ago
For a start, don't try the == operator on reference types like that. It doesn't work. Least of all when the two operands are of different types. And in the case of arrays, don't use the equals method like that; it isn't overridden and you would have to use this instead.
But there is a better way to find whether an array is sorted. You can write your own checking method:-Search my posts for details of utility classes for more explanation. I shall let you complete the method.