| Author |
recursive problem
|
Momo Sawada
Greenhorn
Joined: Dec 10, 2010
Posts: 24
|
|
i'm having a problem with my code... i don't know what to do with it...
it displays stuff like [{09gsd.... how can i make it display the array elements?
thank you!
|
 |
Devaka Cooray
Saloon Keeper
Joined: Jul 29, 2008
Posts: 2729
|
|
Momo Sawada wrote:
Printing an array object doesn't print the containing elements. You can use a for-loop to iterate over the array and print each elements of it.
|
Author of ExamLab (Download) - the free mock exam kit for SCJP / OCPJP
HELP me! -- Home Page -- Twitter Profile -- JavaRanch FAQ -- How to Ask a Question
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32839
|
|
Momo Sawada wrote: . . . it displays stuff like [{09gsd.... how can i make it display the array elements? . . .
If you go through the Java™ Language Specification, you find that an array has . . .
All the members inherited from class Object; the only method of Object that is not inherited is its clone method.
That means it has an un-overridden toString() method. Clicking that last link tells you that you get a printout in the format ClassName@123abc45, which in the case of an array looks like [ClassName@8734eb2a or something. Note that primitive arrays start with [ and one letter, I think chosen from BCDFILSZ. All arrays have an initial [, and I think arrays of arrays start with [[, and similarly more [][][] in the code will produce more [[[ in the printout.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32839
|
|
Devaka Cooray wrote:. . . You can use a for-loop to iterate over the array and print each elements of it.
Lots more information in the Java™ Tutorials, here and here.
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12963
|
|
You can also use:
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
Momo Sawada
Greenhorn
Joined: Dec 10, 2010
Posts: 24
|
|
Devaka Cooray wrote:
Momo Sawada wrote:
Printing an array object doesn't print the containing elements. You can use a for-loop to iterate over the array and print each elements of it.
lol... i almost forgot that... i can't believe i didn't remember it when i had just used it...
thanks a lot!!!
|
 |
 |
|
|
subject: recursive problem
|
|
|