Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert boolean (true or false) to string value in groovy?

Tags:

boolean

groovy

def setOnePlueOne(def user, def booleanValue) {
    updateAnswerAttribute(userRandy, ??????)
    ..
}

so what i have to do to convert that boolean to string and updateAnswerAttribute as "true" or "false" in DB.

Added getter and setter

public Boolean setOnePlueOne() {
    return OnePlueOne;
}
public void getOnePlueOne(Boolean onePlueOne) {
    this.onePlueOne = onePlueOne;

now I need to convert that (Boolean onePlueOne) in string (true or false) and send it through set method to def booleanValue.

def setOnePlueOne(def user, def booleanValue) {
updateAnswerAttribute(userRandy, ??????) this will update or create value in DB 
like image 375
Arpitha Mamidala Avatar asked Aug 20 '15 22:08

Arpitha Mamidala


People also ask

How do you convert a boolean to a string?

To convert Boolean to String in Java, use the toString() method. For this, firstly, we have declared two booleans. String str1 = new Boolean(bool1). toString(); String str2 = new Boolean(bool2).

How do you convert boolean to true or false?

You can convert True and False to strings 'True' and 'False' with str() . Non-empty strings are considered True , so if you convert False to strings with str() and then back to bool type with bool() , it will be True .

How do you convert a boolean to a string in TypeScript?

Use the String object to convert a boolean to a string in TypeScript, e.g. const str = String(bool) . When used as a function, the String object converts the passed in value to a string and returns the result. Copied! The String function takes a value as a parameter and converts it to a string.


2 Answers

The two best ways of doing this are :

  1. String.valueOf(booleanValue)
  2. Boolean.toString(booleanValue)

Though the preferred is the first one as second gives null pointer when booleanValue = null.

Best approach to converting Boolean object to string in java

like image 155
Rahul Babu Avatar answered Oct 15 '22 17:10

Rahul Babu


Use: anyBooleanValue.toString()

Example:

Boolean flag=true
String value=flag.toString()
like image 23
upadhyayRakes Avatar answered Oct 15 '22 17:10

upadhyayRakes