This week's book / license giveaways are in the JDBC and Relational Databases and Java in General forums.
We're giving away four copies each of PostGIS in Action and Java Advanced Topics Training and have the authors on-line!
See this thread and this one for details.
The moose likes Java in General and the fly likes toString with Character Array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "toString with Character Array" Watch "toString with Character Array" New topic
Author

toString with Character Array

Clarence J M Tauro
Ranch Hand

Joined: Aug 09, 2008
Posts: 30
I am not able to get, as to why the below program is printing JAVA



and why this one is printing the address


[ November 20, 2008: Message edited by: Martijn Verburg ]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24189
    
  34

You need to know two things to understand this:

(1) If you call toString() on an array, you always get a String that looks like "[C@24c21495". This is not the address of the array, but rather an indication of the type (the "[C" part), an @ sign, and the return value of calling hashCode() on the array.

(2) There are many different println() methods in the PrintStream class; the compiler chooses which one to call based on the type of the argument. There's a special one for a char[] arguments which prints each character from the array; i.e., it's as if you called

System.out.println(new String(charArray));


[Jess in Action][AskingGoodQuestions]
Clarence J M Tauro
Ranch Hand

Joined: Aug 09, 2008
Posts: 30
Hey.! Got it..

Thanks..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: toString with Character Array