← Quiz: Java Arrays: all 10 questions
Quiz: Java Arrays · Question 4 of 10
Which prints the contents of int[] nums as [1, 2, 3]?
Which prints the contents of int[] nums as [1, 2, 3]?
- A.System.out.println(nums)
- B.System.out.println(Arrays.toString(nums))
- C.System.out.println(nums.toString())
- D.System.out.println(String(nums))
Answer & explanation
Correct answer: System.out.println(Arrays.toString(nums))
Arrays.toString formats the values. Printing the array itself shows a reference.
Can you get the rest right without peeking?
Take the timed Quiz: Java Arrays quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →