Home » Java Boolean toString() Method with Examples

Java Boolean toString() Method with Examples

by Online Tutorials Library

Java Boolean toString() Method

The toString() method of Java Boolean class returns a String illustration of this Boolean.

If the defined object is true, the result returned is “true”, otherwise false is returned.

Syntax:

Parameters:

NA

b – This is the Boolean argument to be converted.

Return Value:

The toString() method returns:

  • A string illustrating the value of this Boolean.
  • The string illustration of the defined Boolean.

Example 1

Test it Now

Output:

Boolean value = true  Hash Code for boolean value = 1231  String value = true  Hash Code for String Value = 3569038  

Example 2

Output:

Enter your percentage.  89  Congratulation! You have passed.  

Example 3

Test it Now

Output:

Your age is 9 years.  Sorry! You are not an adult.  You will be eligible after9year.  

Example 4

Output:

True/False:-  5 months have 30 days.   Ans: true  Answer is wrong.  Because all 11 months (except Feb) have 30 days.  

Example 5

Test it Now

Output:

Error:(7, 23) java: boolean cannot be dereferenced  

Boolean is a primitive data type, its object can’t be used to call Boolean class objects.

Next TopicJava Boolean

You may also like