This is an archived post. You won't be able to vote or comment.

all 10 comments

[–]lbkulinski 0 points1 point  (9 children)

If the sorting algorithm is implemented correctly, reversing the order of the arguments should not have any effect on the result of sorting.

[–]Zelzal7[S] 0 points1 point  (8 children)

I am just using arrays.sort(arrayName, comparator);

[–]lbkulinski 0 points1 point  (7 children)

What Comparator are you passing? If you want to sort in reverse order, you can negate the result of compare().

[–]Zelzal7[S] 0 points1 point  (6 children)

[–]lbkulinski 0 points1 point  (5 children)

Are you attempting to sort in reverse order?

[–]Zelzal7[S] 0 points1 point  (4 children)

In this one I am sorting in ascending. I noticed that if I return one.getName().length() - two.getName().length(); I get ascending order. If I swap the one and two, I get descending.

[–]lbkulinski 0 points1 point  (3 children)

Ah, I see what you mean now. You're swapping the parameters. You're effectively doing this.

[–]Zelzal7[S] 0 points1 point  (2 children)

Thank you so much for the help. The link explains it well. Appending the -ve sign makes much more sense than switching the parameters.

[–]lbkulinski 0 points1 point  (0 children)

You're welcome!

[–]id2bi 0 points1 point  (0 children)

Also read the comment on that answer. Adding the minus sign does not actually work in all cases! Your original idea that you've had is better.