This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread 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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 24183
    
  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
 
Similar Threads
Output missing something...
overriding question
java programming
Mock Exam Dan - Initialization A (Topic)
can you increment letters?