wood burning stoves 2.0
The moose likes Beginning Java and the fly likes Boolean to String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Boolean to String" Watch "Boolean to String" New topic

Boolean to String

Grishma Dube
Ranch Hand

Joined: Jul 01, 2003
Posts: 275
I'm getting a Boolean field, hence getting value as a true, or false.

But when, i want to display that I need to display it as a 'Y' or 'N'. In the getter method for this field, I need to check for true or false. But not sure how will i assign y, n to it


Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Your Boolean field has a method booleanValue() that returns a primitive boolean true or false. You can use that in a test:

Also look into the ternary ? operator. I reserve it for extremely simple situations like this one and am careful not to abuse it in ways that are hard to read. Some people make life easier and just say never use it. You decide.

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

boolean isSomething = ...
String yOrN = isSomething? "y" : "n";

Is that all you're asking?

[Jess in Action][AskingGoodQuestions]
I agree. Here's the link: http://aspose.com/file-tools
subject: Boolean to String
It's not a secret anymore!