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

Discussion

What Arrays.copyOf does when the new length exceeds the original - which of the following is true?

  • A.It repeats the original contents until the new length is filled.
  • B.It leaves the extra positions unset.
  • C.It pads the extra positions with the element type's default value.
  • D.It throws IllegalArgumentException.

Answer: C

The result is always exactly the requested length: shorter truncates and longer pads with zero, false or null as appropriate. That makes it the concise way to grow an array, since a Java array cannot be resized in place.

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

Post your comment

Please log in or register to post a comment.