This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android 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: 18538
    
  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.
 
 
subject: Sytstem.out.format
 
Similar Threads
Printf (not enough resources)
printf string formatting
printf() method clarification required
Logical Operators
simple print statement