• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Boolean to String

 
Grishma Dube
Ranch Hand
Posts: 275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

Regards,

grishma
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
boolean isSomething = ...
String yOrN = isSomething? "y" : "n";

Is that all you're asking?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic