Max Rahder wrote:
Just a word of caution: using simple subtraction for ints can get very nasty if the ints get quite big. Consider the case where h1.getHeight() is Integer.MIN_VALUE, and h2.getHeight() is positive. The result will overflow, and produce nasty results.
If the chances of this exist, the following is much safer (and also applies to long):
But if you know (and can guarantee) that the int values won't get that big, subtracting is not a problem.
sudha swami wrote:Hi, Thanks for the information. The above example has height in ascending order and the name is also in the ascending order.
My requirement is : Height should be in the ascending order and name should be in descending order.
I just gave you an example. You'll have to figure out how to apply it to your situation. Experiment a little.
I implemented the code changes according to your suggestion(return -(previous return value) ) and it is working fine.
Thanks for your suggestion. But i dont understand
"You can just return -(previous return value) except when the previous return value is Integer.MIN_VALUE "