• Post Reply Bookmark Topic Watch Topic
  • New Topic

printf in Java ?  RSS feed

 
Jason Kretzer
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How does the new printf functionality compare to the old C-Style printf? I would assume they are similar but are the format specifiers the same?

Also, does %s also print char arrays or just String?
 
Jeff Bosch
Ranch Hand
Posts: 805
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to the API for the Formatter class, one of three interpretations of the %c format specifier is possible:

- null, which prints "null"
- an object that implements Formattable, then argument.formatTo is invoked
- an object that does not implement Formattable, which is formatted by calling the object's toString method

Remember, an array in Java is an object.


If the argument arg is null, then the result is "null". If arg implements Formattable, then arg.formatTo is invoked. Otherwise, the result is obtained by invoking arg.toString().


Oh, here's the Formatter API link.
[ October 19, 2004: Message edited by: Jeff Bosch ]
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
does %s also print char arrays or just String?


For String datatype and All Object.


%c for char datatype.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!