Java source code examples

Java source code samples. Java code examples.

Convert a boolean value to String

          0 votes

We can use the Boolean wrapper class for converting the boolean value to String.

public class BooleanWrapper {
	public static void main(String[] args) {
		boolean bool = true;
		String str = Boolean.toString(bool);

		System.out.println(str);
	}
}

or

public class BooleanWrapper {
	public static void main(String[] args) {
		boolean bool = true;
		Boolean boolObject = Boolean.valueOf(bool);
		String str = boolObject.toString();

		System.out.println(str);
	}
}

Tags: java.lang

Discuss This Code