Javatpoint Logo
Javatpoint Logo

Java Boolean valueOf() Method

The valueof() method of Java Boolean class returns a Boolean instance corresponding to the defined Boolean or to the defined String.

This method returns Boolean 'true' if the defined Boolean value or String value is true, and returns the Boolean 'false' if the defined Boolean or String value is false.

Syntax:

Parameters:

b - This is a Boolean argument to be passed

s - This is the string argument to be passed.

Return Value:

The valueOf() method returns a Boolean instance corresponding to 'b' or to String 's'.

  • It returns true, if the defined Boolean value (b) or String value(s) is true.
  • It returns false, if the Boolean value b is false
  • It returns false, if the String contains any value other than true.

Example 1

Test it Now

Output:

valueOf() method will return = true
valueOf() method will return = false

Example 2

Output:

Enter the number whose table you want to print : 19
Table of 19 :
19 * 1 = 19
19 * 2 = 38
19 * 3 = 57
19 * 4 = 76
19 * 5 = 95
19 * 6 = 114
19 * 7 = 133
19 * 8 = 152
19 * 9 = 171
19 * 10 = 190

Example 3

Output:

Enter you age
78
You are an adult.
You are eligible to vote.

Example 4

Output:

True/False:
Q. TalMahal is located in Delhi.
Ans false
Incorrect. Because TajMahal is located in Agra.

Example 5

Test it Now

Output:

1. Boolean value for True is true
2. Boolean value for false is false
3. Boolean value for hwhfjh is false

Next TopicJava Boolean





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA