File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

toString with Character Array

 
Clarence J M Tauro
Ranch Hand
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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));
 
Clarence J M Tauro
Ranch Hand
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey.! Got it..

Thanks..
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic