Machine-translated by Google. Questions are authored in English.
Top

Discussion

Consider whether Arrays.sort is stable. Which statement is correct?

  • A.It is stable for neither.
  • B.It is stable for objects but not guaranteed stable for primitives.
  • C.It is stable for primitives but not guaranteed stable for objects.
  • D.It is stable for both.

Answer: B

Object sorting uses a merge sort variant, which the javadoc documents as stable, so equal elements keep their relative order. Primitive sorting uses a quicksort variant where stability is meaningless anyway, since equal primitives are indistinguishable.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.