Java Convert boolean to String

Java Convert boolean to String

We can convert boolean to String in java using String.valueOf(boolean) method.

Alternatively, we can use Boolean.toString(boolean) method which also converts boolean into String.

1) String.valueOf()

The String.valueOf() method converts boolean to String. The valueOf() is the static method of String class. The signature of valueOf() method is given below:

Java boolean to String Example using String.valueOf()

Let's see the simple example of converting boolean to String in java.

Test it Now

Output:

true
false

2) Boolean.toString()

The Boolean.toString() method converts boolean to String. The toString() is the static method of Boolean class. The signature of toString() method is given below:

Java boolean to String Example using Boolean.toString()

Let's see the simple code to convert boolean to String in java using Boolean.toString() method.

Test it Now

Output:

true
false




Latest Courses