Java String valueOf(boolean b) method example

HQ » Java Tutorial » java.lang » String » valueOf(boolean b) method example
Java String valueOf(boolean b) method example 2018-02-19T13:11:53+00:00

java.lang.String valueOf(boolean b)

Description :

This java tutorial shows how to use the valueOf(boolean b) method of String class of java.lang package. This method returns a string representation of boolean data type.

Method Syntax :

public static String valueOf(boolean b)

Parameter Input :

DataType Parameter Description
boolean b method parameter which we are interested to get the string equivalent

Method Returns :

The String valueOf() method with argument boolean returns a new String object. If the value of the boolean parameter is true the result would be “true” otherwise “false”.

Compatibility Version :

Since the beginning

Exception :


Discussion :

The string valueOf(boolean b) method is to get a String equivalent of boolean method parameter. This method be statically accessed which means we should call the method like String.valueOf(boolean value).

Java Code Example :

This example source code demonstrates the use of valueOf(Boolean b) of String class. We have used the contains() method of String class to evaluate if String contains a string “Male”. This is simply to print the value of a boolean datatype. Since the sample string contains a String “Male”, the console output is true.

Sample Output :

Running the valueOf() method example source code of String class will give you the following output

java string indexOf-boolean method example

java string indexOf boolean method example

Exception Scenario :


Suggested Reading List :

References :


Contact Info


Our Goal

JavaTutorialHQ aims to to be The Ultimate Guide on Java with hundreds of examples from basic to advance Topics.

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.