Convert boolean value to String in Java
static String valueOf(boolean b) method of String class can be used to convert a boolean value to String in Java.
For eg. when we pass a boolean value 'true' to valueOf method, it returns a string value 'true'.
Example 1
class BtoSTest{
public static void main(String args[]){
boolean a=false;
String booltoSt=String.valueOf(a);
System.out.println(booltoSt);
}
}
Output 1
false
Example 2
class BtoSTest{
public static void main(String args[]){
boolean b=true;
String booltoSt=String.valueOf(a);
System.out.println(booltoSt);
}
}
Output 2
true