wood burning stoves*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Sytstem.out.format Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Sytstem.out.format" Watch "Sytstem.out.format" New topic
Author

Sytstem.out.format

Mrinal Singhania
Greenhorn

Joined: Sep 30, 2012
Posts: 7
Hi,



The first line prints "true", while the second throws an exception. I don't understand why? AFAIK, booleans are not equivalent to ints/doubles, in that true != 1 and false != 0 in java.

Can someone please explain.

Thanks.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18914
    
  40

Take a look at the javadoc for the java.util.Formatter class, particularly the chart about the behavior for each type.

'b', 'B'
general
If the argument arg is null, then the result is "false". If arg is a boolean or Boolean, then the result is the string returned by String.valueOf(arg). Otherwise, the result is "true".


Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Mrinal Singhania
Greenhorn

Joined: Sep 30, 2012
Posts: 7
Henry Wong wrote:Take a look at the javadoc for the java.util.Formatter class, particularly the chart about the behavior for each type.

'b', 'B'
general
If the argument arg is null, then the result is "false". If arg is a boolean or Boolean, then the result is the string returned by String.valueOf(arg). Otherwise, the result is "true".


Henry


Hi Henry,

Thanks for the reply. And this solves my problem

Regards.
 
Consider Paul's rocket mass heater.
 
subject: Sytstem.out.format