This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
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

Win a copy of Head First Android this week in the Android forum!
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: 14688

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.
I agree. Here's the link:
subject: System.out.format( "%s", new Integer( 123 ));
It's not a secret anymore!