File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Question on deepToString() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Question on deepToString()" Watch "Question on deepToString()" New topic
Author

Question on deepToString()

Thomas Kennedy
Ranch Hand

Joined: Jan 20, 2008
Posts: 137
On the Sun self-assessment for 310-055 there is a question as follows:

Given:
int[] a = {7,9,8};
int[][] aa = {{1,2,3},{6,5,4}};
int[][][] aaa = {{{1,2},{3,4}},{{5,6},{7,8}}};

which will compile?

a. System.out.println(Arrays.deepToString(a));
b. System.out.println(Arrays.deepToString(aa));
c. System.out.println(Arrays.deepToString(aaa));

Now the signature for deepToString() is



So I can see why b & c would compile: they are arrays of arrays, that is, arrays of objects. Is that the reason (a) will not compile, that it is an array of primitives? Am I missing anything here?

I see here http://www.coderanch.com/t/268592/java-programmer-SCJP/certification/todeepArray that Bert says this is not on the exam but I'm not taking any chances.


Costs matter. Justice lies in processes not outcomes. Crime is caused by criminals.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Yep, an int[] is not an Object[]. That's all there is to it.


[Jess in Action][AskingGoodQuestions]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Question on deepToString()