File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes System.out.format( Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "System.out.format( "%s", new Integer( 123 ));" Watch "System.out.format( "%s", new Integer( 123 ));" New topic

System.out.format( "%s", new Integer( 123 ));

joshua antony
Ranch Hand

Joined: Jun 05, 2006
Posts: 117

Although the argument is of type Integer and %s siginifies String why does the above work?

Can someone please explain the concept behind all this.
Christophe Verré

Joined: Nov 24, 2005
Posts: 14687

Integer.toString will be called.
Same as System.out.println( new Integer(123) );

[My Blog]
All roads lead to JavaRanch
joshua antony
Ranch Hand

Joined: Jun 05, 2006
Posts: 117
Thank you.
It is sorta covered in the JavaRanch Style Guide.
subject: System.out.format( "%s", new Integer( 123 ));
Similar Threads
format: why this does not produce exception?
output clarification
Formatting boolean, string with incompatible data types